pub struct SummaryBuilder { /* private fields */ }Expand description
Builder for constructing a Summary from VARIABLE=VALUE lines.
§Example
use pkgsrc::summary::SummaryBuilder;
let path = concat!(env!("CARGO_MANIFEST_DIR"), "/tests/data/summary/mktool.txt");
let input = std::fs::read_to_string(path).expect("failed to read mktool.txt");
assert_eq!(
SummaryBuilder::new()
.vars(input.lines())
.build()
.expect("build failed")
.pkgname(),
"mktool-1.4.2"
);Implementations§
Source§impl SummaryBuilder
impl SummaryBuilder
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new empty SummaryBuilder.
Sourcepub fn vars<I, S>(self, lines: I) -> Self
pub fn vars<I, S>(self, lines: I) -> Self
Add VARIABLE=VALUE lines.
This method is infallible; validation occurs when build is called.
§Example
use pkgsrc::summary::SummaryBuilder;
let path = concat!(env!("CARGO_MANIFEST_DIR"), "/tests/data/summary/mktool.txt");
let input = std::fs::read_to_string(path).expect("failed to read mktool.txt");
assert_eq!(
SummaryBuilder::new()
.vars(input.lines())
.build()
.expect("build failed")
.pkgname(),
"mktool-1.4.2"
);Sourcepub fn allow_unknown(self, yes: bool) -> Self
pub fn allow_unknown(self, yes: bool) -> Self
Allow unknown variables instead of returning an error.
Sourcepub fn allow_incomplete(self, yes: bool) -> Self
pub fn allow_incomplete(self, yes: bool) -> Self
Allow incomplete entries missing required fields.
Sourcepub fn build(self) -> Result<Summary>
pub fn build(self) -> Result<Summary>
Validate and finalize the Summary.
Parses all added variables, validates that all required fields are
present, and returns the completed Summary.
§Errors
Returns Error if the input is invalid. Applications may want to
ignore Error::UnknownVariable if they wish to be future-proof
against potential new additions to the pkg_summary format.
§Examples
use pkgsrc::summary::{Error, SummaryBuilder};
let path = concat!(env!("CARGO_MANIFEST_DIR"), "/tests/data/summary/mktool.txt");
let input = std::fs::read_to_string(path).expect("failed to read mktool.txt");
// Valid pkg_summary data.
assert_eq!(
SummaryBuilder::new()
.vars(input.lines())
.build()
.expect("build failed")
.pkgname(),
"mktool-1.4.2"
);
// Missing required fields.
assert!(matches!(
SummaryBuilder::new()
.vars(["PKGNAME=testpkg-1.0", "COMMENT=Test"])
.build(),
Err(Error::Incomplete { .. })
));
// Contains a line not in VARIABLE=VALUE format.
assert!(matches!(
SummaryBuilder::new()
.vars(["not a valid line"])
.build(),
Err(Error::ParseLine { .. })
));
// Unknown variable name.
assert!(matches!(
SummaryBuilder::new()
.vars(["UNKNOWN=value"])
.build(),
Err(Error::UnknownVariable { .. })
));
// Invalid integer value (with all other required fields present).
assert!(matches!(
SummaryBuilder::new()
.vars([
"BUILD_DATE=2019-08-12",
"CATEGORIES=devel",
"COMMENT=test",
"DESCRIPTION=test",
"MACHINE_ARCH=x86_64",
"OPSYS=NetBSD",
"OS_VERSION=9.0",
"PKGNAME=test-1.0",
"PKGPATH=devel/test",
"PKGTOOLS_VERSION=20091115",
"SIZE_PKG=not_a_number",
])
.build(),
Err(Error::ParseInt { .. })
));Trait Implementations§
Source§impl Clone for SummaryBuilder
impl Clone for SummaryBuilder
Source§fn clone(&self) -> SummaryBuilder
fn clone(&self) -> SummaryBuilder
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for SummaryBuilder
impl Debug for SummaryBuilder
Source§impl Default for SummaryBuilder
impl Default for SummaryBuilder
Source§fn default() -> SummaryBuilder
fn default() -> SummaryBuilder
Returns the “default value” for a type. Read more
Source§impl PartialEq for SummaryBuilder
impl PartialEq for SummaryBuilder
impl Eq for SummaryBuilder
impl StructuralPartialEq for SummaryBuilder
Auto Trait Implementations§
impl Freeze for SummaryBuilder
impl RefUnwindSafe for SummaryBuilder
impl Send for SummaryBuilder
impl Sync for SummaryBuilder
impl Unpin for SummaryBuilder
impl UnwindSafe for SummaryBuilder
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.