Skip to main content

to_string

Function to_string 

Source
pub fn to_string<T: Serialize>(value: &T) -> Result<String>
Expand description

Serialize value into a structprop-formatted String.

Top-level structs and maps produce a flat sequence of key = value / key { … } entries with no enclosing braces. Sequences produce a bare {\n … \n} block.

§Errors

Returns Error::UnsupportedType if T contains raw byte slices, or Error::Message for any other serde-level serialization error.

§Examples

use serde::Serialize;
use serde_structprop::to_string;

#[derive(Serialize)]
struct Cfg { host: String, port: u16 }

let s = to_string(&Cfg { host: "localhost".into(), port: 8080 }).unwrap();
assert!(s.contains("host = localhost"));
assert!(s.contains("port = 8080"));