Struct bonsaidb::core::key::CompositeKeyEncoder
source · pub struct CompositeKeyEncoder<NullHandling = EscapeNullBytes> { /* private fields */ }
Expand description
Encodes multiple KeyEncoding
implementors into a single byte buffer,
preserving the ordering guarantees necessary for Key
.
The produced bytes can be decoded using CompositeKeyDecoder
.
Implementations§
source§impl<NullHandling> CompositeKeyEncoder<NullHandling>where
NullHandling: CompositeKeyNullHandler,
impl<NullHandling> CompositeKeyEncoder<NullHandling>where
NullHandling: CompositeKeyNullHandler,
sourcepub fn encode<'k, K, T>(
&mut self,
value: &'k T
) -> Result<(), CompositeKeyError>
pub fn encode<'k, K, T>( &mut self, value: &'k T ) -> Result<(), CompositeKeyError>
Encodes a single KeyEncoding
implementing value.
let value1 = String::from("hello");
let value2 = 42_u32;
let mut encoder = CompositeKeyEncoder::default();
encoder.encode(&value1).unwrap();
encoder.encode(&value2).unwrap();
let encoded = encoder.finish();
let mut decoder = CompositeKeyDecoder::default_for(ByteSource::Borrowed(&encoded));
let decoded_string = decoder.decode::<String>().unwrap();
assert_eq!(decoded_string, value1);
let decoded_u32 = decoder.decode::<u32>().unwrap();
assert_eq!(decoded_u32, value2);
decoder.finish().expect("trailing bytes");
source§impl CompositeKeyEncoder<AllowNullBytes>
impl CompositeKeyEncoder<AllowNullBytes>
sourcepub const fn allowing_null_bytes() -> CompositeKeyEncoder<AllowNullBytes>
pub const fn allowing_null_bytes() -> CompositeKeyEncoder<AllowNullBytes>
Returns an encoder that allows null bytes in variable length fields.
See CompositeKeyFieldContainsNullByte
for information about the edge
cases this may introduce.
source§impl CompositeKeyEncoder<DenyNullBytes>
impl CompositeKeyEncoder<DenyNullBytes>
sourcepub const fn denying_null_bytes() -> CompositeKeyEncoder<DenyNullBytes>
pub const fn denying_null_bytes() -> CompositeKeyEncoder<DenyNullBytes>
Returns an encoder that denies null bytes in variable length fields by returning an error when any null bytes are detected.
Trait Implementations§
source§impl Default for CompositeKeyEncoder
impl Default for CompositeKeyEncoder
source§fn default() -> CompositeKeyEncoder
fn default() -> CompositeKeyEncoder
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl<NullHandling> RefUnwindSafe for CompositeKeyEncoder<NullHandling>where
NullHandling: RefUnwindSafe,
impl<NullHandling> Send for CompositeKeyEncoder<NullHandling>where
NullHandling: Send,
impl<NullHandling> Sync for CompositeKeyEncoder<NullHandling>where
NullHandling: Sync,
impl<NullHandling> Unpin for CompositeKeyEncoder<NullHandling>where
NullHandling: Unpin,
impl<NullHandling> UnwindSafe for CompositeKeyEncoder<NullHandling>where
NullHandling: UnwindSafe,
Blanket Implementations§
§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more