Skip to main content

KeyRef

Trait KeyRef 

Source
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§

Source

fn key_bytes(&self) -> RawBytes

The stored-key bytes this value addresses.

Provided Methods§

Source

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".

Implementations on Foreign Types§

Source§

impl KeyRef for [u8]

Source§

impl KeyRef for str

Implementors§

Source§

impl<T: KeyEnDe> KeyRef for T