Skip to content

Commit

Permalink
Add circle-ci configuration, formatting fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
kyren committed Jul 5, 2019
1 parent e36068c commit 992b3d5
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 10 deletions.
36 changes: 36 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
version: 2

jobs:
build:
docker:
- image: circleci/rust:latest
steps:
- checkout
- run:
name: Version information
command: rustc --version; cargo --version; rustup --version
- run:
name: Calculate dependencies
command: cargo generate-lockfile
- restore_cache:
keys:
- cargo-cache-{{ arch }}-{{ checksum "Cargo.lock" }}
- run:
name: Check Formatting
command: |
rustup component add rustfmt
rustfmt --version
cargo fmt --all -- --check --color=auto
- run:
name: Build all targets
command: cargo build --all --all-targets
- run:
name: Run all tests
command: cargo test --all
- save_cache:
paths:
- /usr/local/cargo/registry
- target/debug/.fingerprint
- target/debug/build
- target/debug/deps
key: cargo-cache-{{ arch }}-{{ checksum "Cargo.lock" }}
20 changes: 14 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use std::{
borrow::Borrow,
hash::{BuildHasher, Hash, Hasher},
marker,
mem::{self, MaybeUninit},
ops::{Index, IndexMut},
ptr,
marker,
};

use hashbrown::{hash_map, HashMap};
Expand Down Expand Up @@ -184,7 +184,7 @@ where
RawEntryMut::Occupied(mut occupied) => {
occupied.to_back();
Some(occupied.insert(v))
},
}
RawEntryMut::Vacant(vacant) => {
vacant.insert(k, v);
None
Expand Down Expand Up @@ -278,7 +278,10 @@ impl<K, V, S> Drop for LinkedHashMap<K, V, S> {
}

impl<'a, K, V, S, Q: ?Sized> Index<&'a Q> for LinkedHashMap<K, V, S>
where K: Hash + Eq + Borrow<Q>, S: BuildHasher, Q: Eq + Hash
where
K: Hash + Eq + Borrow<Q>,
S: BuildHasher,
Q: Eq + Hash,
{
type Output = V;

Expand All @@ -288,7 +291,10 @@ impl<'a, K, V, S, Q: ?Sized> Index<&'a Q> for LinkedHashMap<K, V, S>
}

impl<'a, K, V, S, Q: ?Sized> IndexMut<&'a Q> for LinkedHashMap<K, V, S>
where K: Hash + Eq + Borrow<Q>, S: BuildHasher, Q: Eq + Hash
where
K: Hash + Eq + Borrow<Q>,
S: BuildHasher,
Q: Eq + Hash,
{
fn index_mut(&mut self, index: &'a Q) -> &mut V {
self.get_mut(index).expect("no entry found for key")
Expand All @@ -304,7 +310,7 @@ impl<K: Hash + Eq + Clone, V: Clone, S: BuildHasher + Clone> Clone for LinkedHas
}

impl<K: Hash + Eq, V, S: BuildHasher> Extend<(K, V)> for LinkedHashMap<K, V, S> {
fn extend<I: IntoIterator<Item=(K, V)>>(&mut self, iter: I) {
fn extend<I: IntoIterator<Item = (K, V)>>(&mut self, iter: I) {
for (k, v) in iter {
self.insert(k, v);
}
Expand Down Expand Up @@ -778,7 +784,9 @@ impl<'a, K, V> DoubleEndedIterator for Iter<'a, K, V> {
}

impl<'a, K, V> ExactSizeIterator for Iter<'a, K, V> {
fn len(&self) -> usize { self.remaining }
fn len(&self) -> usize {
self.remaining
}
}

// A ZST that asserts that the inner HashMap will not do its own key hashing
Expand Down
12 changes: 8 additions & 4 deletions tests/test.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use hashlink::{LinkedHashMap, Entry};
use hashlink::{Entry, LinkedHashMap};

#[test]
fn test_index() {
Expand Down Expand Up @@ -155,11 +155,15 @@ fn test_iter() {

#[test]
fn test_borrow() {
#[derive(PartialEq, Eq, Hash)] struct Foo(Bar);
#[derive(PartialEq, Eq, Hash)] struct Bar(i32);
#[derive(PartialEq, Eq, Hash)]
struct Foo(Bar);
#[derive(PartialEq, Eq, Hash)]
struct Bar(i32);

impl ::std::borrow::Borrow<Bar> for Foo {
fn borrow(&self) -> &Bar { &self.0 }
fn borrow(&self) -> &Bar {
&self.0
}
}

let mut map = LinkedHashMap::new();
Expand Down

0 comments on commit 992b3d5

Please sign in to comment.