pub trait IntKey: Copy {
type Int: Int;
const PRIME: Self::Int;
// Required method
fn into_int(self) -> Self::Int;
}
Expand description
A type that can be used as key for IntMap
.
The type needs to be integer based, i.e. it can be represented by a unique integer.
This can be useful for types that wraps integers for type safety (e.g. Ipv4Addr
)
or for enforcing invariants (e.g. NonZeroU64
).
§Example
use intmap::{IntKey, IntMap};
#[derive(Clone, Copy)]
struct MyKey(u64);
impl IntKey for MyKey {
type Int = u64;
// You could also choose another prime number
const PRIME: Self::Int = u64::PRIME;
fn into_int(self) -> Self::Int {
self.0
}
}
let map: IntMap<MyKey, f32> = IntMap::new();
Required Associated Constants§
Required Associated Types§
Required 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.