pub trait Field: Shape + Sized {
// Required methods
fn write(&self, b: &mut Builder) -> Result<()>;
fn read(d: Doc<'_>) -> Result<Self>;
// Provided method
fn missing(name: &str) -> Result<Self> { ... }
}Expand description
A type that can be a field of a document.
The encoding is YOJB and not a Rust layout, so what goes in the store is what a document is: an object with named fields, readable by the RESP surface and by another language’s binding without either of them knowing what Rust is.
Required Methods§
Provided Methods§
Sourcefn missing(name: &str) -> Result<Self>
fn missing(name: &str) -> Result<Self>
What to do when the field is not in the document at all.
An error for everything except Option, which is the whole point of
having an Option: a field that may be absent says so in the type, and
every other field being absent is a document that does not match the
shape it was stored under.
§Errors
Code::Corrupt, unless the type is an Option.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".
Implementations on Foreign Types§
Source§impl Field for u64
A u64 is the one integer that does not fit, because JSON has one number
type and it is signed. Anything past i64::MAX is refused on the way in
rather than rounded through a float on the way out.
impl Field for u64
A u64 is the one integer that does not fit, because JSON has one number
type and it is signed. Anything past i64::MAX is refused on the way in
rather than rounded through a float on the way out.
Source§impl<T: Field> Field for Option<T>
A field that may be absent, which is the only type whose absence is not an
error. None is stored as null rather than left out, so a document always
has the fields its shape says it has.
impl<T: Field> Field for Option<T>
A field that may be absent, which is the only type whose absence is not an
error. None is stored as null rather than left out, so a document always
has the fields its shape says it has.