pub trait KeyRef {
// Required method
fn key_bytes(&self) -> RawBytes;
// Provided method
fn as_byte_slice(&self) -> Option<&[u8]> { ... }
}Expand description
Encoding of a borrowed key form for lookups in maps with KeyEnDe
keys — map.get(&q) where K: Borrow<Q>, like HashMap::get.
Implemented for every KeyEnDe type (encoding itself) and for str
and [u8], whose encodings are byte-identical to String’s and
Vec<u8>’s. Byte slices also expose their contents so Mapx can resolve
them against the owning key codec (fixed arrays have no length prefix).
An implementation for another borrowed form must encode exactly as its
owner does, or lookups can miss or address another key.
Required Methods§
Provided Methods§
Sourcefn as_byte_slice(&self) -> Option<&[u8]>
fn as_byte_slice(&self) -> Option<&[u8]>
Byte-slice contents, when this is a borrowed byte-slice query.
Unlike key_bytes, these bytes have no length
prefix. Maps validate them against the owning key before encoding it.
Other borrowed forms use the default encoding contract above.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".