pub fn to_string<T>(value: &T) -> Result<String, SeError>where
T: Serialize,Available on crate feature
xml only.Expand description
Serialize a T into a XML string with compact representation.
Always use Xml to serialize XML response data.
§Example
use rocket::serde::{Deserialize, Serialize, xml};
#[derive(Debug, PartialEq, Deserialize, Serialize)]
#[serde(crate = "rocket::serde")]
struct Data<'r> {
framework: &'r str,
stars: usize,
}
let data = Data {
framework: "Rocket",
stars: 5,
};
let string = xml::to_string(&data).unwrap();
let data: Data = xml::from_str(&string).unwrap();
assert_eq!(data, Data { framework: "Rocket", stars: 5, });§Errors
Serialization fails if T’s Serialize implementation fails.