pub trait Serializer: Sized {
    type Ok;
    type Error: Error;
    type SerializeArray: SerializeArray<Ok = Self::Ok, Error = Self::Error>;
    type SerializeMap: SerializeMap<Ok = Self::Ok, Error = Self::Error>;
    type SerializeSeqProduct: SerializeSeqProduct<Ok = Self::Ok, Error = Self::Error>;
    type SerializeNamedProduct: SerializeNamedProduct<Ok = Self::Ok, Error = Self::Error>;

Show 23 methods // Required methods fn serialize_bool(self, v: bool) -> Result<Self::Ok, Self::Error>; fn serialize_u8(self, v: u8) -> Result<Self::Ok, Self::Error>; fn serialize_u16(self, v: u16) -> Result<Self::Ok, Self::Error>; fn serialize_u32(self, v: u32) -> Result<Self::Ok, Self::Error>; fn serialize_u64(self, v: u64) -> Result<Self::Ok, Self::Error>; fn serialize_u128(self, v: u128) -> Result<Self::Ok, Self::Error>; fn serialize_i8(self, v: i8) -> Result<Self::Ok, Self::Error>; fn serialize_i16(self, v: i16) -> Result<Self::Ok, Self::Error>; fn serialize_i32(self, v: i32) -> Result<Self::Ok, Self::Error>; fn serialize_i64(self, v: i64) -> Result<Self::Ok, Self::Error>; fn serialize_i128(self, v: i128) -> Result<Self::Ok, Self::Error>; fn serialize_f32(self, v: f32) -> Result<Self::Ok, Self::Error>; fn serialize_f64(self, v: f64) -> Result<Self::Ok, Self::Error>; fn serialize_str(self, v: &str) -> Result<Self::Ok, Self::Error>; fn serialize_bytes(self, v: &[u8]) -> Result<Self::Ok, Self::Error>; fn serialize_array( self, len: usize ) -> Result<Self::SerializeArray, Self::Error>; fn serialize_map( self, len: usize ) -> Result<Self::SerializeMap, Self::Error>; fn serialize_seq_product( self, len: usize ) -> Result<Self::SerializeSeqProduct, Self::Error>; fn serialize_named_product( self, len: usize ) -> Result<Self::SerializeNamedProduct, Self::Error>; fn serialize_variant<T: Serialize + ?Sized>( self, tag: u8, name: Option<&str>, value: &T ) -> Result<Self::Ok, Self::Error>; unsafe fn serialize_bsatn( self, ty: &AlgebraicType, bsatn: &[u8] ) -> Result<Self::Ok, Self::Error>; unsafe fn serialize_bsatn_in_chunks<'a, I: Clone + Iterator<Item = &'a [u8]>>( self, ty: &AlgebraicType, total_bsatn_len: usize, bsatn: I ) -> Result<Self::Ok, Self::Error>; unsafe fn serialize_str_in_chunks<'a, I: Clone + Iterator<Item = &'a [u8]>>( self, total_len: usize, string: I ) -> Result<Self::Ok, Self::Error>;
}
Expand description

A data format that can deserialize any data structure supported by SATs.

The Serializer trait in SATS performs the same function as serde::Serializer in serde. See the documentation of serde::Serializer for more information of the data model.

Required Associated Types§

source

type Ok

The output type produced by this Serializer during successful serialization.

Most serializers that produce text or binary output should set Ok = () and serialize into an io::Write or buffer contained within the Serializer instance. Serializers that build in-memory data structures may be simplified by using Ok to propagate the data structure around.

source

type Error: Error

The error type when some error occurs during serialization.

source

type SerializeArray: SerializeArray<Ok = Self::Ok, Error = Self::Error>

Type returned from serialize_array for serializing the contents of the array.

source

type SerializeMap: SerializeMap<Ok = Self::Ok, Error = Self::Error>

Type returned from serialize_map for serializing the contents of the map.

source

type SerializeSeqProduct: SerializeSeqProduct<Ok = Self::Ok, Error = Self::Error>

Type returned from serialize_seq_product for serializing the contents of the unnamed product.

source

type SerializeNamedProduct: SerializeNamedProduct<Ok = Self::Ok, Error = Self::Error>

Type returned from serialize_named_product for serializing the contents of the named product.

Required Methods§

source

fn serialize_bool(self, v: bool) -> Result<Self::Ok, Self::Error>

Serialize a bool value.

source

fn serialize_u8(self, v: u8) -> Result<Self::Ok, Self::Error>

Serialize a u8 value.

source

fn serialize_u16(self, v: u16) -> Result<Self::Ok, Self::Error>

Serialize a u16 value.

source

fn serialize_u32(self, v: u32) -> Result<Self::Ok, Self::Error>

Serialize a u32 value.

source

fn serialize_u64(self, v: u64) -> Result<Self::Ok, Self::Error>

Serialize a u64 value.

source

fn serialize_u128(self, v: u128) -> Result<Self::Ok, Self::Error>

Serialize a u128 value.

source

fn serialize_i8(self, v: i8) -> Result<Self::Ok, Self::Error>

Serialize an i8 value.

source

fn serialize_i16(self, v: i16) -> Result<Self::Ok, Self::Error>

Serialize an i16 value.

source

fn serialize_i32(self, v: i32) -> Result<Self::Ok, Self::Error>

Serialize an i32 value.

source

fn serialize_i64(self, v: i64) -> Result<Self::Ok, Self::Error>

Serialize an i64 value.

source

fn serialize_i128(self, v: i128) -> Result<Self::Ok, Self::Error>

Serialize an i128 value.

source

fn serialize_f32(self, v: f32) -> Result<Self::Ok, Self::Error>

Serialize an f32 value.

source

fn serialize_f64(self, v: f64) -> Result<Self::Ok, Self::Error>

Serialize an f64 value.

source

fn serialize_str(self, v: &str) -> Result<Self::Ok, Self::Error>

Serialize a &str string slice.

source

fn serialize_bytes(self, v: &[u8]) -> Result<Self::Ok, Self::Error>

Serialize a &[u8] byte slice.

source

fn serialize_array( self, len: usize ) -> Result<Self::SerializeArray, Self::Error>

Begin to serialize a variably sized array. This call must be followed by zero or more calls to SerializeArray::serialize_element, then a call to SerializeArray::end.

The argument is the number of elements in the sequence.

source

fn serialize_map(self, len: usize) -> Result<Self::SerializeMap, Self::Error>

Begin to serialize a variably sized map. This call must be followed by zero or more calls to [SerializeMap::serialize_element], then a call to SerializeMap::end.

The argument is the number of elements in the map.

source

fn serialize_seq_product( self, len: usize ) -> Result<Self::SerializeSeqProduct, Self::Error>

Begin to serialize a product with unnamed fields. This call must be followed by zero or more calls to SerializeSeqProduct::serialize_element, then a call to SerializeSeqProduct::end.

The argument is the number of fields in the product.

source

fn serialize_named_product( self, len: usize ) -> Result<Self::SerializeNamedProduct, Self::Error>

Begin to serialize a product with named fields. This call must be followed by zero or more calls to SerializeNamedProduct::serialize_element, then a call to SerializeNamedProduct::end.

The argument is the number of fields in the product.

source

fn serialize_variant<T: Serialize + ?Sized>( self, tag: u8, name: Option<&str>, value: &T ) -> Result<Self::Ok, Self::Error>

Serialize a sum value provided the chosen tag, name, and value.

source

unsafe fn serialize_bsatn( self, ty: &AlgebraicType, bsatn: &[u8] ) -> Result<Self::Ok, Self::Error>

Serialize the given bsatn encoded data of type ty.

This is a concession to performance, allowing some implementations to write the buffer directly.

§Safety
  • AlgebraicValue::decode(ty, &mut bsatn).is_ok(). That is, bsatn encodes a valid element of ty.
source

unsafe fn serialize_bsatn_in_chunks<'a, I: Clone + Iterator<Item = &'a [u8]>>( self, ty: &AlgebraicType, total_bsatn_len: usize, bsatn: I ) -> Result<Self::Ok, Self::Error>

Serialize the given bsatn encoded data of type ty.

The data is provided as an iterator of chunks, at arbitrary boundaries, with a total concatenated length of total_bsatn_len which callers can assume.

An implementation of this method is semantically the same as:

let mut buf = Vec::new();
for chunk in bsatn {
    buf.extend(chunk);
}
ser.serialize_bsatn(&buf);

This method is a concession to performance, allowing some implementations to write the buffer directly.

The parameter I is required to be Clone only for debug_assert! purposes.

§Safety
  • total_bsatn_len == bsatn.map(|c| c.len()).sum() <= isize::MAX
  • Let buf be defined as above, i.e., the bytes of bsatn concatenated. Then AlgebraicValue::decode(ty, &mut buf).is_ok(). That is, buf encodes a valid element of ty.
source

unsafe fn serialize_str_in_chunks<'a, I: Clone + Iterator<Item = &'a [u8]>>( self, total_len: usize, string: I ) -> Result<Self::Ok, Self::Error>

Serialize the given string.

The string is provided as an iterator of chunks, at arbitrary boundaries, with a total concatenated length of total_len which callers can trust.

An implementation of this method is semantically the same as:

let mut buf = Vec::new();
for chunk in string {
    buf.extend(chunk);
}
let str = unsafe { core::str::from_utf8_unchecked(&buf) };
ser.serialize_str(str);

This method is a concession to performance, allowing some implementations to write the buffer directly.

The parameter I is required to be Clone only for debug_assert! purposes.

§Safety
  • total_len == string.map(|c| c.len()).sum() <= isize::MAX
  • Let buf be the bytes of string concatenated. Then core::str::from_utf8(&buf).is_ok(). That is, buf is valid UTF-8. Note however that individual chunks need not be valid UTF-8, as multi-byte characters may be split across chunk boundaries.

Object Safety§

This trait is not object safe.

Implementors§