al8n / caches-rs

This is a Rust implementation for popular caches (support no_std).
104 stars 14 forks source link

Many methods return lifetimes that are not tied to the lifetime of self #11

Closed goffrie closed 1 year ago

goffrie commented 1 year ago

These use &'_ self when they should use &'a self (resp. mut).

Sample program that segfaults when it shouldn't compile:

//! ```cargo
//! [dependencies]
//! caches = { version = "0.2" }
//! ```

use caches::{Cache, RawLRU};

fn main() {
    let mut lru = RawLRU::new(2).unwrap();
    lru.put(1, "foo".to_string());
    lru.put(2, "bar".to_string());
    let iter = lru.iter();
    drop(lru);
    println!("{:?}", iter.collect::<Vec<_>>());
}
goffrie commented 1 year ago

Actually it's not just RawLRU - all the methods on trait Cache that return references have the same problem.

al8n commented 1 year ago

Hi, thanks for reporting. Fix the lifetime bug in 0.2.6 error.