Struct hashlru::Dump

source ·
pub struct Dump<K, V> {
    pub capacity: usize,
    pub data: Vec<(K, V)>,
}
Expand description

Complete dump of a LRU cache, easily (de)serializable.

It reflects the complete current state of the cache, including key/value pairs but also capacity and order.

Can be used to import/export the cache and serialize/unserialize it.

§Examples

use hashlru::{Cache, Dump};

let mut cache: Cache<&str, usize> = Cache::new(10);
cache.insert("x", 1);
cache.insert("y", 10);
cache.insert("z", 100);

let dump: Dump<&str, usize> = Dump::from(cache);
assert_eq!("Dump { capacity: 10, data: [(\"x\", 1), (\"y\", 10), (\"z\", 100)] }", format!("{:?}", dump));
let restore: Cache<&str, usize> = Cache::from(dump);
assert_eq!(10, restore.capacity());
assert_eq!("[x: 1, y: 10, z: 100]", format!("{}", &restore));

Fields§

§capacity: usize§data: Vec<(K, V)>

Trait Implementations§

source§

impl<K: Debug, V: Debug> Debug for Dump<K, V>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<'de, K, V> Deserialize<'de> for Dump<K, V>
where K: Deserialize<'de>, V: Deserialize<'de>,

source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl<K, V> From<Cache<K, V>> for Dump<K, V>
where K: Hash + Eq,

source§

fn from(cache: Cache<K, V>) -> Dump<K, V>

Converts to this type from the input type.
source§

impl<K, V> From<Dump<K, V>> for Cache<K, V>
where K: Hash + Eq,

source§

fn from(dump: Dump<K, V>) -> Cache<K, V>

Converts to this type from the input type.
source§

impl<K, V> From<Dump<K, V>> for SyncCache<K, V>
where K: Hash + Eq + Clone, V: Clone,

source§

fn from(dump: Dump<K, V>) -> SyncCache<K, V>

Converts to this type from the input type.
source§

impl<K, V> PartialEq for Dump<K, V>
where K: Hash + Eq, V: PartialEq,

source§

fn eq(&self, other: &Self) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<K, V> Serialize for Dump<K, V>
where K: Serialize, V: Serialize,

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl<K, V> Eq for Dump<K, V>
where K: Hash + Eq + Clone, V: Eq,

Auto Trait Implementations§

§

impl<K, V> Freeze for Dump<K, V>

§

impl<K, V> RefUnwindSafe for Dump<K, V>

§

impl<K, V> Send for Dump<K, V>
where K: Send, V: Send,

§

impl<K, V> Sync for Dump<K, V>
where K: Sync, V: Sync,

§

impl<K, V> Unpin for Dump<K, V>
where K: Unpin, V: Unpin,

§

impl<K, V> UnwindSafe for Dump<K, V>
where K: UnwindSafe, V: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,