Function serde_any::from_slice_any [−][src]
pub fn from_slice_any<'a, T>(s: &'a [u8]) -> Result<T, Error> where
T: for<'de> Deserialize<'de>,
Deserialize from a byte slice using any supported format
Errors
If the specified format is not supported, this function returns
Error::UnsupportedFormat
.
If the conversion itself fails, the format-specific variant of Error
will be returned, with the underlying error as its cause.
Example
#[macro_use] extern crate serde; extern crate serde_any; extern crate failure; use failure::Error; use serde_any::Format; #[derive(Deserialize, Debug)] struct Person { name: String, knowledge: u32, } fn main() -> Result<(), Error> { let data = b"{ \"name\": \"Jon Snow\", \"knowledge\": 0 }"; let person: Person = serde_any::from_slice_any(data)?; println!("{:#?}", person); Ok(()) }