22 releases

0.2.4 Nov 16, 2024
0.2.2 Oct 26, 2024
0.1.13 Jul 16, 2024
0.1.8 Feb 22, 2024
0.1.7 Nov 29, 2023

#270 in Parser implementations

Download history 3214/week @ 2024-08-22 2091/week @ 2024-08-29 2323/week @ 2024-09-05 1467/week @ 2024-09-12 1849/week @ 2024-09-19 1799/week @ 2024-09-26 1163/week @ 2024-10-03 666/week @ 2024-10-10 1023/week @ 2024-10-17 842/week @ 2024-10-24 798/week @ 2024-10-31 1057/week @ 2024-11-07 2820/week @ 2024-11-14 675/week @ 2024-11-21 590/week @ 2024-11-28 810/week @ 2024-12-05

5,105 downloads per month
Used in 14 crates (9 directly)

Apache-2.0

595KB
2.5K SLoC

Parsers and editors for deb822 style files

This crate contains parsers and editors for RFC822 style file as used in Debian.

Four related crates that build on this one are:

  • debian-control: A parser and editor for Debian control files, apt lists.
  • debian-copyright: A parser and editor for Debian copyright files.
  • dep3: A parser and editor for Debian DEP-3 headers.
  • r-description: A parser and editor for R DESCRIPTION files.

Example

use deb822_lossless::Deb822;
use std::str::FromStr;

let input = r#"Package: deb822-lossless
Maintainer: Jelmer Vernooij <jelmer@debian.org>
Section: rust

Package: deb822-lossless
Architecture: any
Description: Lossless parser for deb822 style files.
  This parser can be used to parse files in the deb822 format, while preserving
  all whitespace and comments. It is based on the [rowan] library, which is a
  lossless parser library for Rust.
"#;

let deb822 = Deb822::from_str(input).unwrap();
assert_eq!(deb822.paragraphs().count(), 2);

A derive-macro is also provided for easily defining more Deb822-derived types:

#[cfg(feature = "derive")]
{
use deb822_lossless::{FromDeb822, ToDeb822};

#[derive(FromDeb822, ToDeb822, Debug, PartialEq)]
struct Test {
    #[deb822(field = "Package")]
    package: String,
    architecture: Option<String>,

    #[deb822(field = "Description")]
    description: String,
}

let input = r#"Package: deb822-lossless
Architecture: any
Description: Lossless parser for deb822 style files.
  This parser can be used to parse files in the deb822 format, while preserving
  all whitespace and comments. It is based on the [rowan] library, which is a
  lossless parser library for Rust.
"#;

use deb822_lossless::Paragraph;
use deb822_lossless::convert::FromDeb822Paragraph;
let parser: Paragraph = input.parse().unwrap();
let test: Test = FromDeb822Paragraph::from_paragraph(&parser).unwrap();

assert_eq!(test.package, "deb822-lossless");
}

Dependencies

~3.5–5.5MB
~103K SLoC