Trait cuprate_database::Key
source · pub trait Key: Storable + Sized {
type Primary: Storable;
// Provided method
fn compare(left: &[u8], right: &[u8]) -> Ordering { ... }
}Expand description
Database Table key metadata.
Purely compile time information for database table keys.
Required Associated Types§
Provided Methods§
sourcefn compare(left: &[u8], right: &[u8]) -> Ordering
fn compare(left: &[u8], right: &[u8]) -> Ordering
Compare 2 Key’s against each other.
By default, this does a straight byte comparison, not a comparison of the key’s value.
assert_eq!(
<u64 as Key>::compare([0].as_slice(), [1].as_slice()),
std::cmp::Ordering::Less,
);
assert_eq!(
<u64 as Key>::compare([1].as_slice(), [1].as_slice()),
std::cmp::Ordering::Equal,
);
assert_eq!(
<u64 as Key>::compare([2].as_slice(), [1].as_slice()),
std::cmp::Ordering::Greater,
);Object Safety§
This trait is not object safe.