restore_registry: &RESTORE_REGISTRY
  restore_cache:
    key: registry
save_registry: &SAVE_REGISTRY
  save_cache:
    key: registry-{{ .BuildNum }}
    paths:
    - /usr/local/cargo/registry/index
deps_key: &DEPS_KEY
  key: deps-{{ checksum "~/rust-version" }}-{{ checksum "Cargo.lock" }}
restore_deps: &RESTORE_DEPS
  restore_cache:
    <<: *DEPS_KEY
save_deps: &SAVE_DEPS
  save_cache:
    <<: *DEPS_KEY
    paths:
    - target
    - /usr/local/cargo/registry/cache

version: 2
jobs:
  build:
    docker:
      - image: rustlang/rust:nightly
        environment:
          RUSTFLAGS: -D warnings
      - image: sfackler/rust-postgres-test:5
    steps:
      - checkout
      - run: rustup component add rustfmt clippy
      - *RESTORE_REGISTRY
      - run: cargo generate-lockfile
      - *SAVE_REGISTRY
      - run: rustc --version > ~/rust-version
      - *RESTORE_DEPS
      - run: cargo fmt --all -- --check
      - run: cargo clippy --all --all-targets --all-features
      - run: cargo test --all
      - run: cargo test --manifest-path tokio-postgres/Cargo.toml --no-default-features
      - run: cargo test --manifest-path tokio-postgres/Cargo.toml --all-features
      - *SAVE_DEPS

restore_registry: &RESTORE_REGISTRY
  restore_cache:
    key: registry
save_registry: &SAVE_REGISTRY
  save_cache:
    key: registry-{{ .BuildNum }}
    paths:
    - /usr/local/cargo/registry/index
deps_key: &DEPS_KEY
  key: deps-{{ checksum "~/rust-version" }}-{{ checksum "Cargo.lock" }}
restore_deps: &RESTORE_DEPS
  restore_cache:
    <<: *DEPS_KEY
save_deps: &SAVE_DEPS
  save_cache:
    <<: *DEPS_KEY
    paths:
    - target
    - /usr/local/cargo/registry/cache

version: 2
jobs:
  build:
    docker:
      - image: rust:1.39.0
        environment:
          RUSTFLAGS: -D warnings
      - image: sfackler/rust-postgres-test:5
    steps:
      - checkout
      - run: rustup component add rustfmt clippy
      - *RESTORE_REGISTRY
      - run: cargo generate-lockfile
      - *SAVE_REGISTRY
      - run: rustc --version > ~/rust-version
      - *RESTORE_DEPS
      - run: cargo fmt --all -- --check
      - run: cargo clippy --all --all-targets --all-features
      - run: cargo test --all
      - run: cargo test --manifest-path tokio-postgres/Cargo.toml --no-default-features
      - run: cargo test --manifest-path tokio-postgres/Cargo.toml --all-features
      - *SAVE_DEPS

Switch off nightly in CI
Switch off nightly in CI
