Function serde_any::ser::to_string_pretty [−][src]
pub fn to_string_pretty<T>(value: &T, format: Format) -> Result<String, Error> where
T: Serialize,
Serialize to a pretty-printed String
Not all serialization formats support pretty printing.
In such cases, the output from this function will be identical to the output
of to_string
.
Errors
If serialization fails, the format-specific Error
variant 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_string_pretty(&bran, Format::Toml)?; println!("{}", data); assert_eq!(&data[..], "name = \'Brandon Stark\'\nknowledge = 100\n"); Ok(()) }