Skip to main content

Field

Trait Field 

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

Source

fn write(&self, b: &mut Builder) -> Result<()>

Write this value into the document being built.

§Errors

Code::Invalid for a value the document encoding cannot hold, which is a u64 past i64::MAX and nothing else so far.

Source

fn read(d: Doc<'_>) -> Result<Self>

Read this value back out.

§Errors

Code::Corrupt when the stored value is not this type, which means the collection disagrees with its own shape.

Provided Methods§

Source

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 String

Source§

fn write(&self, b: &mut Builder) -> Result<()>

Source§

fn read(d: Doc<'_>) -> Result<String>

Source§

impl Field for bool

Source§

fn write(&self, b: &mut Builder) -> Result<()>

Source§

fn read(d: Doc<'_>) -> Result<bool>

Source§

impl Field for f32

Source§

fn write(&self, b: &mut Builder) -> Result<()>

Source§

fn read(d: Doc<'_>) -> Result<f32>

Source§

impl Field for f64

Source§

fn write(&self, b: &mut Builder) -> Result<()>

Source§

fn read(d: Doc<'_>) -> Result<f64>

Source§

impl Field for i8

Source§

fn write(&self, b: &mut Builder) -> Result<()>

Source§

fn read(d: Doc<'_>) -> Result<i8>

Source§

impl Field for i16

Source§

fn write(&self, b: &mut Builder) -> Result<()>

Source§

fn read(d: Doc<'_>) -> Result<i16>

Source§

impl Field for i32

Source§

fn write(&self, b: &mut Builder) -> Result<()>

Source§

fn read(d: Doc<'_>) -> Result<i32>

Source§

impl Field for i64

Source§

fn write(&self, b: &mut Builder) -> Result<()>

Source§

fn read(d: Doc<'_>) -> Result<i64>

Source§

impl Field for u8

Source§

fn write(&self, b: &mut Builder) -> Result<()>

Source§

fn read(d: Doc<'_>) -> Result<u8>

Source§

impl Field for u16

Source§

fn write(&self, b: &mut Builder) -> Result<()>

Source§

fn read(d: Doc<'_>) -> Result<u16>

Source§

impl Field for u32

Source§

fn write(&self, b: &mut Builder) -> Result<()>

Source§

fn read(d: Doc<'_>) -> Result<u32>

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.

Source§

fn write(&self, b: &mut Builder) -> Result<()>

Source§

fn read(d: Doc<'_>) -> Result<u64>

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.

Source§

fn write(&self, b: &mut Builder) -> Result<()>

Source§

fn read(d: Doc<'_>) -> Result<Option<T>>

Source§

fn missing(_name: &str) -> Result<Option<T>>

Source§

impl<T: Field> Field for Vec<T>

Source§

fn write(&self, b: &mut Builder) -> Result<()>

Source§

fn read(d: Doc<'_>) -> Result<Vec<T>>

Implementors§