Function serde_any::to_vec [−][src]
pub fn to_vec<T>(value: &T, format: Format) -> Result<Vec<u8>, Error> where
T: Serialize,
Serialize to a byte vector
Errors
If serialization fails, the format-specific error type is returned, with the underlying error as its cause.
Example
#[macro_use] extern crate serde; extern crate serde_any; extern crate failure; use serde_any::Format; use failure::Error; #[derive(Serialize, Debug)] struct Person { name: String, knowledge: u32, } fn main() -> Result<(), Error> { let bran = Person { name: "Brandon Stark".to_string(), knowledge: 100, }; let data = serde_any::to_vec(&bran, Format::Toml)?; assert_eq!( data, b"name = \"Brandon Stark\"\nknowledge = 100\n".to_vec() ); Ok(()) }