Expand description
§Format ‘deb822’ for serde
Implement serializer and deserializer for serde.
#[derive(Serialize, Deserialize)]
// In deb822, we not have standard, some field named on PascalCase and other
// with title-capitalized kebab-case (not supported by serde)
#[serde(rename_all = "PascalCase")]
struct Info<'a> {
// Extract value with zero-copy
#[serde(rename="Borrow-Str")]
borrow_str: &'a str,
// or by copy
string: String,
// 'yes' and 'no' value are parsed as bool
flag: bool,
// number (int and float) are parsed with [`FromStr::from_str`]
size: u64,
// When value is 2-tuple, first element is the first line and second element
// is followed line (The second value can't be borrowed, because one space
// at start line must be removed)
description: (&'a str, String),
// You can also extract each line separated
description_alt: (&'a str, Vec<&'a str>),
// or not extract separate first-line
description_alt2: Vec<&'a str>,
}
let s = r#"
Borrow-Str: string one
#Comment are removed
#first space after colon (:) are removed if present
String: string two
Flag: yes
Size: 25677
Description: title line
continuation line
on two line
DescriptionAlt: title line
continuation line
on two line
DescriptionAlt2: title line
continuation line
on two line
"#;
let _: Info = deb822::from_str(s).unwrap();
Re-exports§
pub use value::Value;