pub trait Serializer: Sized {
type Ok;
type Error: Error;
type SerializeArray: SerializeArray<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 26 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_u256(self, v: U256) -> 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_i256(self, v: I256) -> 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_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>(
self,
tag: u8,
name: Option<&str>,
value: &T,
) -> Result<Self::Ok, Self::Error>
where T: Serialize + ?Sized;
// Provided methods
fn serialize_named_product_raw(
self,
value: &ValueWithType<'_, ProductValue>,
) -> Result<Self::Ok, Self::Error> { ... }
fn serialize_variant_raw(
self,
sum: &ValueWithType<'_, SumValue>,
) -> Result<Self::Ok, Self::Error> { ... }
unsafe fn serialize_bsatn<Ty>(
self,
ty: &Ty,
bsatn: &[u8],
) -> Result<Self::Ok, Self::Error>
where WithTypespace<'a, Ty>: for<'a, 'de> DeserializeSeed<'de>,
<WithTypespace<'a, Ty> as DeserializeSeed<'de>>::Output: for<'a, 'de> Into<AlgebraicValue> { ... }
unsafe fn serialize_bsatn_in_chunks<'a, Ty, I>(
self,
ty: &Ty,
total_bsatn_len: usize,
bsatn: I,
) -> Result<Self::Ok, Self::Error>
where I: Clone + Iterator<Item = &'a [u8]>,
WithTypespace<'b, Ty>: for<'b, 'de> DeserializeSeed<'de>,
<WithTypespace<'b, Ty> as DeserializeSeed<'de>>::Output: for<'b, 'de> Into<AlgebraicValue> { ... }
unsafe fn serialize_str_in_chunks<'a, I>(
self,
total_len: usize,
string: I,
) -> Result<Self::Ok, Self::Error>
where I: Clone + Iterator<Item = &'a [u8]> { ... }
}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 on the data model.
Required Associated Types§
Sourcetype Ok
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.
Sourcetype SerializeArray: SerializeArray<Ok = Self::Ok, Error = Self::Error>
type SerializeArray: SerializeArray<Ok = Self::Ok, Error = Self::Error>
Type returned from serialize_array
for serializing the contents of the array.
Sourcetype SerializeSeqProduct: SerializeSeqProduct<Ok = Self::Ok, Error = Self::Error>
type SerializeSeqProduct: SerializeSeqProduct<Ok = Self::Ok, Error = Self::Error>
Type returned from serialize_seq_product
for serializing the contents of the unnamed product.
Sourcetype SerializeNamedProduct: SerializeNamedProduct<Ok = Self::Ok, Error = Self::Error>
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§
Sourcefn serialize_str(self, v: &str) -> Result<Self::Ok, Self::Error>
fn serialize_str(self, v: &str) -> Result<Self::Ok, Self::Error>
Serialize a &str string slice.
Sourcefn serialize_bytes(self, v: &[u8]) -> Result<Self::Ok, Self::Error>
fn serialize_bytes(self, v: &[u8]) -> Result<Self::Ok, Self::Error>
Serialize a &[u8] byte slice.
Sourcefn serialize_array(
self,
len: usize,
) -> Result<Self::SerializeArray, Self::Error>
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.
Sourcefn serialize_seq_product(
self,
len: usize,
) -> Result<Self::SerializeSeqProduct, Self::Error>
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.
Sourcefn serialize_named_product(
self,
len: usize,
) -> Result<Self::SerializeNamedProduct, Self::Error>
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.
Provided Methods§
Sourcefn serialize_named_product_raw(
self,
value: &ValueWithType<'_, ProductValue>,
) -> Result<Self::Ok, Self::Error>
fn serialize_named_product_raw( self, value: &ValueWithType<'_, ProductValue>, ) -> Result<Self::Ok, Self::Error>
Serialize a product with named fields.
Allow to override the default serialization for where we need to switch the output format,
see crate::satn::TypedWriter.
Sourcefn serialize_variant_raw(
self,
sum: &ValueWithType<'_, SumValue>,
) -> Result<Self::Ok, Self::Error>
fn serialize_variant_raw( self, sum: &ValueWithType<'_, SumValue>, ) -> Result<Self::Ok, Self::Error>
Serialize a sum value
Allow to override the default serialization for where we need to switch the output format,
see crate::satn::TypedWriter.
Sourceunsafe fn serialize_bsatn<Ty>(
self,
ty: &Ty,
bsatn: &[u8],
) -> Result<Self::Ok, Self::Error>where
WithTypespace<'a, Ty>: for<'a, 'de> DeserializeSeed<'de>,
<WithTypespace<'a, Ty> as DeserializeSeed<'de>>::Output: for<'a, 'de> Into<AlgebraicValue>,
unsafe fn serialize_bsatn<Ty>(
self,
ty: &Ty,
bsatn: &[u8],
) -> Result<Self::Ok, Self::Error>where
WithTypespace<'a, Ty>: for<'a, 'de> DeserializeSeed<'de>,
<WithTypespace<'a, Ty> as DeserializeSeed<'de>>::Output: for<'a, 'de> Into<AlgebraicValue>,
Serialize the given bsatn encoded data of type ty.
This is a concession to performance, allowing some implementations to write the buffer directly.
§Safety
decode(ty, &mut bsatn).is_ok(). That is,bsatnencodes a valid element ofty. It’s up to the caller to arrangeTysuch that this holds.
Sourceunsafe fn serialize_bsatn_in_chunks<'a, Ty, I>(
self,
ty: &Ty,
total_bsatn_len: usize,
bsatn: I,
) -> Result<Self::Ok, Self::Error>where
I: Clone + Iterator<Item = &'a [u8]>,
WithTypespace<'b, Ty>: for<'b, 'de> DeserializeSeed<'de>,
<WithTypespace<'b, Ty> as DeserializeSeed<'de>>::Output: for<'b, 'de> Into<AlgebraicValue>,
unsafe fn serialize_bsatn_in_chunks<'a, Ty, I>(
self,
ty: &Ty,
total_bsatn_len: usize,
bsatn: I,
) -> Result<Self::Ok, Self::Error>where
I: Clone + Iterator<Item = &'a [u8]>,
WithTypespace<'b, Ty>: for<'b, 'de> DeserializeSeed<'de>,
<WithTypespace<'b, Ty> as DeserializeSeed<'de>>::Output: for<'b, 'de> Into<AlgebraicValue>,
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
bufbe defined as above, i.e., the bytes ofbsatnconcatenated. Thendecode(ty, &mut buf).is_ok(). That is,bufencodes a valid element ofty. It’s up to the caller to arrangeTysuch that this holds.
Sourceunsafe fn serialize_str_in_chunks<'a, I>(
self,
total_len: usize,
string: I,
) -> Result<Self::Ok, Self::Error>
unsafe fn serialize_str_in_chunks<'a, I>( 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
bufbe the bytes ofstringconcatenated. Thencore::str::from_utf8(&buf).is_ok(). That is,bufis valid UTF-8. Note however that individual chunks need not be valid UTF-8, as multi-byte characters may be split across chunk boundaries.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.