Function serialize

Source
pub fn serialize<T>(
    subject: &T,
    format: &SerializationFormat,
) -> Result<Vec<u8>, SerializationError>
where T: ?Sized + Serialize,
Expand description

Attempts to serialise subject into the specified format and returns the result as a Vec<u8>.

§Arguments

  • subject: The data structure to serialise.
  • format: A SerializationFormat that indicates which serialisation format to use.

returns: Result<Vec<u8>>

§Errors

This method returns a SerializationError if any of the steps for serialisation fails. See SerializationError for specific details on each error scenario.

§Examples



serialize(&Foo { bar: "baz".to_string() }, &SerializationFormat::JSON)?;