deb822

Crates.iodeb822
lib.rsdeb822
version0.2.2
created_at2022-09-17 13:32:36.873701+00
updated_at2025-07-09 12:40:49.794836+00
description(De)Serialization of Deb822 file
homepage
repositoryhttps://gitlab.com/loskraes/rust-deb822
max_upload_size
id668177
size55,888
LoskrAES (loskraes)

documentation

README

Format 'deb822' for serde

Implement serializer and deserializer for serde.

# use serde_derive::{Deserialize, Serialize};
#[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();

Commit count: 0

cargo fmt