Function serde_any::to_file [−][src]
pub fn to_file<T, P>(path: P, value: &T) -> Result<(), Error> where
T: Serialize,
P: AsRef<Path>,
Serialize to a file
Errors
If the serialization format cannot be inferred from the file name,
UnsupportedFileExtension
is returned.
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; use std::fs::File; #[derive(Serialize, Debug)] struct Person { name: String, knowledge: u32, } fn main() -> Result<(), Error> { let bran = Person { name: "Brandon Stark".to_string(), knowledge: 100, }; serde_any::to_file("bran.yaml", &bran)?; Ok(()) }