Skip to content

Commit

Permalink
Merge pull request #149 from jeromefroe/jerome/fix-github-action
Browse files Browse the repository at this point in the history
Fix CI config
  • Loading branch information
jeromefroe committed Jul 20, 2022
2 parents febcddb + 67c3c2f commit 3edfbf4
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 33 deletions.
43 changes: 18 additions & 25 deletions .github/workflows/main.yml
Expand Up @@ -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
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -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

Expand Down
14 changes: 7 additions & 7 deletions src/lib.rs
Expand Up @@ -356,6 +356,7 @@ impl<K: Hash + Eq, V, S: BuildHasher> LruCache<K, V, S> {

// 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<LruEntry<K, V>>) {
if self.len() == self.cap() {
// if the cache is full, remove the last entry so we can use it for the new key
Expand Down Expand Up @@ -474,7 +475,7 @@ impl<K: Hash + Eq, V, S: BuildHasher> LruCache<K, V, S> {
/// 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,
{
Expand Down Expand Up @@ -526,7 +527,7 @@ impl<K: Hash + Eq, V, S: BuildHasher> LruCache<K, V, S> {
{
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`
Expand All @@ -552,7 +553,7 @@ impl<K: Hash + Eq, V, S: BuildHasher> LruCache<K, V, S> {
{
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 }),
}
}

Expand Down Expand Up @@ -915,10 +916,9 @@ impl<K, V, S> Drop for LruCache<K, V, S> {
});
// 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) };
}
}

Expand Down

0 comments on commit 3edfbf4

Please sign in to comment.