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

rfc822-like

RFC822-like encoding used in conrol files implemented for serde

4 releases

0.2.1 Dec 20, 2021
0.2.0 Dec 13, 2021
0.1.1 Dec 13, 2021
0.1.0 Aug 5, 2021

#1932 in Parser implementations

Download history 34/week @ 2023-12-18 22/week @ 2023-12-25 113/week @ 2024-01-01 153/week @ 2024-01-08 98/week @ 2024-01-15 40/week @ 2024-01-22 195/week @ 2024-01-29 179/week @ 2024-02-05 73/week @ 2024-02-12 137/week @ 2024-02-19 215/week @ 2024-02-26 121/week @ 2024-03-04 93/week @ 2024-03-11 171/week @ 2024-03-18 102/week @ 2024-03-25 159/week @ 2024-04-01

531 downloads per month
Used in 2 crates (via assorted-debian-utils)

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

~1–1.6MB
~31K SLoC