diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 213ef14..8099e67 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -6,49 +6,42 @@ on: name: CI +# Adapted from recipe: https://github.com/actions-rs/meta/blob/master/recipes/matrix.md#workflow. jobs: ci: - runs-on: [ubuntu-latest, windows-latest, macOS-latest] + runs-on: ubuntu-latest + strategy: + matrix: + rust: + - stable + - beta + - nightly + - 1.56.0 # MSRV steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v2 - uses: actions-rs/toolchain@v1 with: profile: minimal - toolchain: stable + toolchain: ${{ matrix.rust }} + override: true components: rustfmt, clippy - uses: actions-rs/cargo@v1 with: - command: fmt - args: --all -- --check - - - uses: actions-rs/install@v0.1 - with: - crate: cargo-hack - version: latest - use-tool-cache: true + command: build - uses: actions-rs/cargo@v1 with: - command: hack - args: check --workspace --ignore-private --each-feature --no-dev-deps + command: test - uses: actions-rs/cargo@v1 with: - command: check - args: --workspace --all-targets --all-features + command: fmt + args: --all -- --check - uses: actions-rs/cargo@v1 with: - command: test - - - uses: actions-rs/clippy-check@v1 - with: - token: ${{ secrets.GITHUB_TOKEN }} - args: --all-features - - - uses: actions-rs/audit-check@v1 - with: - token: ${{ secrets.GITHUB_TOKEN }} + command: clippy + args: -- -D warnings diff --git a/README.md b/README.md index 3f33cec..cf1855e 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ An implementation of a LRU cache. The cache supports `put`, `get`, `get_mut` and all of which are O(1). This crate was heavily influenced by the [LRU Cache implementation in an earlier version of Rust's std::collections crate]. -The MSRV for this crate is 1.36.0. +The MSRV for this crate is 1.56.0. ## Example diff --git a/src/lib.rs b/src/lib.rs index f002a88..7f09dbe 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -356,6 +356,7 @@ impl LruCache { // Used internally to swap out a node if the cache is full or to create a new node if space // is available. Shared between `put`, `push`, and `get_or_insert`. + #[allow(clippy::type_complexity)] fn replace_or_create_node(&mut self, k: K, v: V) -> (Option<(K, V)>, Box>) { if self.len() == self.cap() { // if the cache is full, remove the last entry so we can use it for the new key @@ -474,7 +475,7 @@ impl LruCache { /// assert_eq!(cache.get_or_insert(1, ||"a"), Some(&"a")); /// assert_eq!(cache.get_or_insert(1, ||"b"), Some(&"a")); /// ``` - pub fn get_or_insert<'a, F>(&'a mut self, k: K, f: F) -> Option<&'a V> + pub fn get_or_insert<'a, F>(&mut self, k: K, f: F) -> Option<&'a V> where F: FnOnce() -> V, { @@ -526,7 +527,7 @@ impl LruCache { { self.map .get(k) - .map(|node| unsafe { &(*(*node).val.as_ptr()) as &V }) + .map(|node| unsafe { &(*node.val.as_ptr()) as &V }) } /// Returns a mutable reference to the value corresponding to the key in the cache or `None` @@ -552,7 +553,7 @@ impl LruCache { { match self.map.get_mut(k) { None => None, - Some(node) => Some(unsafe { &mut (*(*node).val.as_mut_ptr()) as &mut V }), + Some(node) => Some(unsafe { &mut (*node.val.as_mut_ptr()) as &mut V }), } } @@ -915,10 +916,9 @@ impl Drop for LruCache { }); // We rebox the head/tail, and because these are maybe-uninit // they do not have the absent k/v dropped. - - let _head = unsafe { *Box::from_raw(self.head) }; - let _tail = unsafe { *Box::from_raw(self.tail) }; - + + let _head = unsafe { *Box::from_raw(self.head) }; + let _tail = unsafe { *Box::from_raw(self.tail) }; } }