#debian-package #debian #file-format #rfc822 #serde

rfc822-like

RFC822-like encoding used in control files implemented for serde

6 releases

0.2.3 Sep 6, 2024
0.2.2 Jun 29, 2024
0.2.1 Dec 20, 2021
0.1.1 Dec 13, 2021
0.1.0 Aug 5, 2021

#248 in Parser implementations

Download history 121/week @ 2024-08-20 195/week @ 2024-08-27 727/week @ 2024-09-03 480/week @ 2024-09-10 215/week @ 2024-09-17 490/week @ 2024-09-24 302/week @ 2024-10-01 966/week @ 2024-10-08 866/week @ 2024-10-15 483/week @ 2024-10-22 365/week @ 2024-10-29 186/week @ 2024-11-05 122/week @ 2024-11-12 105/week @ 2024-11-19 209/week @ 2024-11-26 164/week @ 2024-12-03

642 downloads per month
Used in 3 crates (2 directly)

MITNFA license

76KB
1.5K SLoC

Rust library for handling RFC822-like format used in Debian

About

This crate implements the file format inpired by RFC822 that is used in Debian packages. It is the format of the debian/control files in packages and Packages file of apt. It is called rfc822-like instead of just rfc822 because Debian does not claim to implement RFC822 exactly and this crate is focused on working with Debian tools, not parsing exact RFC822 file format. Frankly, I didn't even bother to read RFC822 itself.

If you need to strictly parse RFC822, I suggest you to fork this crate and fix whatever differences there are. I'm not interested in maintaining strict RFC822 crate, so don't send PRs for that but I'm willing to put common pieces into their own crate. If you're interested in this approach feel free to file a PR (or ask beforehand if you have questions).

Note that this crate is currently not optimized for performance. There are multiple places where allocation could be avoided and other optimizations may be missing. It's absolutely fine for my own use cases, and probably will be for yours as well. If you need it to be faster or just want to have fun improving its performance I'll be happy to accept PRs.

The API is currently not set in stone and may change over time. Basic steps to minimize the impact of changes were taken (e.g. encapsulation of Error type).

Example

Check the crate documentation for more examples and detailed explanation.

use rfc822_like::de::Deserializer;
use serde::Deserialize;

let input = "Package: foo
Description: The Foo

Package: bar
Description: The Bar
";

let mut reader = input.as_bytes();

#[derive(Debug, Eq, PartialEq, serde_derive::Deserialize)]
#[serde(rename_all = "PascalCase")]
struct Record {
    package: String,
    description: String,
}

let expected = vec![
    Record {
        package: "foo".to_owned(),
        description:"The Foo".to_owned(),
    },
    Record {
        package: "bar".to_owned(),
        description: "The Bar".to_owned(),
    },
];

let deserialized = <Vec<Record>>::deserialize(Deserializer::new(&mut reader)).unwrap();
assert_eq!(deserialized, expected);

MSRV

Whatever Rust version is available in the latest Debian stable, currently 1.41.1.

License

MITNFA

Dependencies

~0.7–1.3MB
~25K SLoC