pub trait SparseContainer: Sized {
type Input;
type Output;
// Required methods
fn get(&self, input: &Self::Input) -> Option<&Self::Output>;
fn put(&mut self, input: Self::Input, output: Self::Output) -> &Self::Output;
// Provided method
fn has(&self, input: &Self::Input) -> bool { ... }
}
Expand description
A generic trait for anything that would like to be used in a [GenericCache
], allowing easy
extensibility using a container not covered by this library.
[HashCache
] and [BTreeCache
] are both just using GenericCache
under the hood, by
implementing this trait on HashMap
and BTreeMap
.
If this trait doesn’t quite fit with your container, you can also implement fully your own
[FnCache
], which requires a bit more work than using this trait, but gives you full
generality. This is how [VecCache
] is implemented, because it is not sparse, and must fill
all earlier indices.
Required Associated Types§
Required Methods§
Provided Methods§
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.