pub trait SerializeStruct {
type Ok;
type Error: Error;
// Required methods
fn serialize_field<T>(
&mut self,
key: &'static str,
value: &T,
) -> Result<(), Self::Error>
where T: ?Sized + Serialize;
fn serialize_fixed_array_field<V, T>(
&mut self,
key: &'static str,
value: V,
size: TypeSize,
) -> Result<(), Self::Error>
where V: AsRef<[T]> + Serialize,
T: Serialize;
fn end(self) -> Result<Self::Ok, Self::Error>;
// Provided methods
fn skip_field<T>(
&mut self,
key: &'static str,
value: &T,
) -> Result<(), Self::Error>
where T: ?Sized + Serialize { ... }
fn pad_field<T>(
&mut self,
x86_pads: &T,
x64_pads: &T,
) -> Result<(), Self::Error>
where T: ?Sized + AsRef<[u8]> { ... }
fn skip_fixed_array_field<V, T>(
&mut self,
key: &'static str,
value: V,
size: TypeSize,
) -> Result<(), Self::Error>
where V: AsRef<[T]> + Serialize,
T: Serialize { ... }
fn serialize_array_field<V, T>(
&mut self,
key: &'static str,
value: V,
size: TypeSize,
) -> Result<(), Self::Error>
where V: AsRef<[T]> + Serialize,
T: Serialize { ... }
fn skip_array_field<V, T>(
&mut self,
key: &'static str,
value: V,
size: TypeSize,
) -> Result<(), Self::Error>
where V: AsRef<[T]> + Serialize,
T: Serialize { ... }
}
Expand description
Returned from Serializer::serialize_struct
.
The example data format presented on the website demonstrates an
implementation of SerializeStruct
for a basic JSON data format.
§Flatten is unsupportable
If the parent is a ptr type, the process of simply writing the parent cannot be used as it is because the data writing of the ptr destination is waiting after the writing of all fields.
Therefore, serialize
of the parent struct cannot be reused.
Required Associated Types§
Required Methods§
Sourcefn serialize_field<T>(
&mut self,
key: &'static str,
value: &T,
) -> Result<(), Self::Error>
fn serialize_field<T>( &mut self, key: &'static str, value: &T, ) -> Result<(), Self::Error>
Serialize a struct field.
Provided Methods§
Sourcefn skip_field<T>(
&mut self,
key: &'static str,
value: &T,
) -> Result<(), Self::Error>
fn skip_field<T>( &mut self, key: &'static str, value: &T, ) -> Result<(), Self::Error>
Process for fields with SERIALIZE_IGNORED
flag.
- XML: Replaced by a comment and the actual data is not displayed.
- Bytes: the data itself is read/written
The default implementation does nothing.
Sourcefn pad_field<T>(
&mut self,
x86_pads: &T,
x64_pads: &T,
) -> Result<(), Self::Error>
fn pad_field<T>( &mut self, x86_pads: &T, x64_pads: &T, ) -> Result<(), Self::Error>
Processing for padding to serialize binary data
The default implementation does nothing.
Sourcefn skip_fixed_array_field<V, T>(
&mut self,
key: &'static str,
value: V,
size: TypeSize,
) -> Result<(), Self::Error>
fn skip_fixed_array_field<V, T>( &mut self, key: &'static str, value: V, size: TypeSize, ) -> Result<(), Self::Error>
Process for fields with SERIALIZE_IGNORED
flag.
The default implementation same as skip_field
Sourcefn serialize_array_field<V, T>(
&mut self,
key: &'static str,
value: V,
size: TypeSize,
) -> Result<(), Self::Error>
fn serialize_array_field<V, T>( &mut self, key: &'static str, value: V, size: TypeSize, ) -> Result<(), Self::Error>
Serialize a struct field for array.
- XML: add
numelements
attribute tohkparam
and write vec contents. - Bytes: Alloc meta(ptr size + size + capAndFlags) bytes. (x86: 12, x64: 16) & Serialize pointed data.
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.