Skip to main content

Crate pkgsrc_kv

Crate pkgsrc_kv 

Source
Expand description

Type-safe KEY=VALUE parsing.

This crate provides the runtime types for parsing KEY=VALUE formatted input — Span, KvError, KvWarning, and the FromKv extension trait — together with the Kv derive macro (enabled by the default derive feature), which generates a parse method for a struct.

Because the derive macro and the runtime it targets live in the same crate, depending on pkgsrc-kv is all that is required to derive Kv: there is no separate runtime crate to add.

use pkgsrc_kv::Kv;

#[derive(Kv)]
struct Package {
    pkgname: String,
    #[kv(variable = "SIZE_PKG")]
    size: u64,
    #[kv(multiline)]
    description: Vec<String>,
    homepage: Option<String>,
}

let pkg = Package::parse("PKGNAME=foo-1.0\nSIZE_PKG=42\n")?;

Structs§

KvWarning
A non-fatal problem encountered while parsing.
Span
A byte offset and length in the input, for error reporting.

Enums§

KvError
Errors that can occur during parsing.

Traits§

FromKv
Trait for types that can be parsed from a KEY=VALUE string.

Type Aliases§

Result
A Result type alias using KvError.

Derive Macros§

Kv
Derive macro for parsing KEY=VALUE formatted input into a struct.