pub trait Value: Debug {
type SelfType<'a>: Debug + 'a
where Self: 'a;
type AsBytes<'a>: AsRef<[u8]> + 'a
where Self: 'a;
const NICHE: Option<&'static [u8]> = None;
// Required methods
fn fixed_width() -> Option<usize>;
fn from_bytes<'a>(data: &'a [u8]) -> Self::SelfType<'a>
where Self: 'a;
fn as_bytes<'a, 'b: 'a>(value: &'a Self::SelfType<'b>) -> Self::AsBytes<'a>
where Self: 'b;
fn type_name() -> TypeName;
}Expand description
Types that implement this trait can be used as values in a redb table
Provided Associated Constants§
Sourceconst NICHE: Option<&'static [u8]> = None
const NICHE: Option<&'static [u8]> = None
A byte string that as_bytes() never returns, if the type declares one.
Implementations must ensure that as_bytes() never returns it, for any value. A fixed
width type’s niche must be exactly fixed_width() bytes long; a
variable width type’s may be any length, including empty. The default, None, declares
no niche.
Container types may use it as an encoding that no value of Self occupies: Option<Self>,
for example, encodes None as it, in place of a tag byte. Declaring a niche changes the
type name of Option<Self>, so it is not equivalent to Option of the type without one.
Required Associated Types§
Sourcetype SelfType<'a>: Debug + 'awhere
Self: 'a,
type SelfType<'a>: Debug + 'awhere
Self: 'a,
SelfType<'a> must be the same type as Self with all lifetimes replaced with ’a
type AsBytes<'a>: AsRef<[u8]> + 'awhere
Self: 'a,
Required Methods§
Sourcefn fixed_width() -> Option<usize>
fn fixed_width() -> Option<usize>
Width of a fixed type, or None for variable width
Sourcefn from_bytes<'a>(data: &'a [u8]) -> Self::SelfType<'a>where
Self: 'a,
fn from_bytes<'a>(data: &'a [u8]) -> Self::SelfType<'a>where
Self: 'a,
Deserializes data Implementations may return a view over data, or an owned type
Note: Implementations may assume that data is the return value of as_bytes(&v) for some v of type Self.
Sourcefn as_bytes<'a, 'b: 'a>(value: &'a Self::SelfType<'b>) -> Self::AsBytes<'a>where
Self: 'b,
fn as_bytes<'a, 'b: 'a>(value: &'a Self::SelfType<'b>) -> Self::AsBytes<'a>where
Self: 'b,
Serialize the value to a slice
Note: Implementations must ensure that as_bytes() and from_bytes() are inverses.
Specifically, for any value v and data returned from as_bytes(&v),
as_bytes(from_bytes(data)) must equal data.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".