Skip to main content

BufferValue

Trait BufferValue 

Source
pub trait BufferValue: Sized {
    const FIXED_WIDTH: Option<FixedWidth> = None;

    // Required methods
    fn write_value(&self, w: &mut BufferWriter);
    unsafe fn read_value(
        r: &mut BufferReader<'_>,
    ) -> Result<Self, BufferDecodeError>;

    // Provided method
    fn encoded_len(&self) -> usize { ... }
}
Expand description

A value that can serialize itself into (and decode itself from) the WeaveFFI buffer format.

The #[weaveffi::record], #[weaveffi::enumeration], and #[weaveffi::error] expansions implement this for annotated types, and blanket implementations below cover primitives, String, Option<T>, Vec<T> (bytes are Vec<u8>), the map types, and Arc<T> (an interface object token), so nested composites compose automatically.

Provided Associated Constants§

Source

const FIXED_WIDTH: Option<FixedWidth> = None

Some when this type’s encoding is its little-endian memory layout (see FixedWidth). Leave the default.

Required Methods§

Source

fn write_value(&self, w: &mut BufferWriter)

Append this value’s encoding to w.

Source

unsafe fn read_value( r: &mut BufferReader<'_>, ) -> Result<Self, BufferDecodeError>

Decode one value of this type from r.

§Errors

Returns an error when the buffer is exhausted or holds invalid data for this type.

§Safety

Unless r was built with BufferReader::token_free, every object token the value contains must carry one strong reference to a live object of the token’s type that hasn’t been adopted yet; reading adopts it. Generated thunks satisfy this because the ABI requires every token a consumer writes to come from a fresh _clone, and they decode each buffer exactly once.

Provided Methods§

Source

fn encoded_len(&self) -> usize

The exact number of bytes write_value appends, used to size encodings up front. The default of 0 is a valid (if slower) hint; every built-in and generated implementation is exact.

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 BufferValue for String

Source§

fn encoded_len(&self) -> usize

Source§

fn write_value(&self, w: &mut BufferWriter)

Source§

unsafe fn read_value( r: &mut BufferReader<'_>, ) -> Result<Self, BufferDecodeError>

Source§

impl BufferValue for bool

Source§

fn encoded_len(&self) -> usize

Source§

fn write_value(&self, w: &mut BufferWriter)

Source§

unsafe fn read_value( r: &mut BufferReader<'_>, ) -> Result<Self, BufferDecodeError>

Source§

impl BufferValue for f32

Source§

impl BufferValue for f64

Source§

impl BufferValue for i8

Source§

impl BufferValue for i16

Source§

impl BufferValue for i32

Source§

impl BufferValue for i64

Source§

impl BufferValue for u8

Source§

impl BufferValue for u16

Source§

impl BufferValue for u32

Source§

impl BufferValue for u64

Source§

impl<K: BufferValue + Hash + Eq, V: BufferValue> BufferValue for HashMap<K, V>

Source§

fn encoded_len(&self) -> usize

Source§

fn write_value(&self, w: &mut BufferWriter)

Source§

unsafe fn read_value( r: &mut BufferReader<'_>, ) -> Result<Self, BufferDecodeError>

Source§

impl<K: BufferValue + Ord, V: BufferValue> BufferValue for BTreeMap<K, V>

Source§

fn encoded_len(&self) -> usize

Source§

fn write_value(&self, w: &mut BufferWriter)

Source§

unsafe fn read_value( r: &mut BufferReader<'_>, ) -> Result<Self, BufferDecodeError>

Source§

impl<T: BufferValue> BufferValue for Option<T>

Source§

fn encoded_len(&self) -> usize

Source§

fn write_value(&self, w: &mut BufferWriter)

Source§

unsafe fn read_value( r: &mut BufferReader<'_>, ) -> Result<Self, BufferDecodeError>

Source§

impl<T: BufferValue> BufferValue for Vec<T>

Source§

fn encoded_len(&self) -> usize

Source§

fn write_value(&self, w: &mut BufferWriter)

Source§

unsafe fn read_value( r: &mut BufferReader<'_>, ) -> Result<Self, BufferDecodeError>

Source§

impl<T> BufferValue for Arc<T>

An interface object inside a buffer: a u64 token carrying one strong reference. Writing clones the Arc; reading adopts the reference, so a buffer holding tokens must be decoded exactly once (the generated thunks guarantee this). A zero token is a contract violation and decodes as an error, and so does any token read through a token_free reader.

Source§

fn encoded_len(&self) -> usize

Source§

fn write_value(&self, w: &mut BufferWriter)

Source§

unsafe fn read_value( r: &mut BufferReader<'_>, ) -> Result<Self, BufferDecodeError>

Implementors§