[][src]Struct pkgsrc::summary::Summaries

pub struct Summaries { /* fields omitted */ }

A collection of pkg_summary(5) entries.

Each pkg_summary entry should be separated by a single blank line.

The Write trait is implemented, and is the method by which an existing pkg_summary file can be parsed into a new Summaries.

Display is also implemented so printing the newly created collection will result in a correctly formed pkg_summary file.

Example

use pkgsrc::summary::Summaries;
use unindent::unindent;

let mut pkgsummary = Summaries::new();
let pkginfo = unindent(r#"
    BUILD_DATE=2019-08-12 15:58:02 +0100
    CATEGORIES=devel pkgtools
    COMMENT=This is a test
    DESCRIPTION=A test description
    DESCRIPTION=
    DESCRIPTION=This is a multi-line variable
    MACHINE_ARCH=x86_64
    OPSYS=Darwin
    OS_VERSION=18.7.0
    PKGNAME=testpkg-1.0
    PKGPATH=pkgtools/testpkg
    PKGTOOLS_VERSION=20091115
    SIZE_PKG=4321
    "#);
/*
 * Obviously 3 identical entries is useless, but serves as an example.
 */
let input = format!("{}\n{}\n{}\n", pkginfo, pkginfo, pkginfo);
std::io::copy(&mut input.as_bytes(), &mut pkgsummary);

/*
 * Output should match what we received.
 */
let output = format!("{}", pkgsummary);
assert_eq!(input.as_bytes(), output.as_bytes());
assert_eq!(pkgsummary.entries().len(), 3);

/*
 * Use each Summary entry to emulate pkg_info output.  This will hopefully
 * be implemented as a proper Iterator at some point.  Note that these
 * values are safe to unwrap as they are required variables and have been
 * checked to exist when creating the entries.
 */
for sum in pkgsummary.entries() {
    println!("{:20} {}", sum.pkgname().unwrap(), sum.comment().unwrap());
}

Methods

impl Summaries[src]

Important traits for Summaries
pub fn new() -> Summaries[src]

Return a new Summaries with default values.

pub fn entries(&self) -> &Vec<Summary>[src]

Return vector of parsed Summary records.

pub fn entries_mut(&mut self) -> &mut Vec<Summary>[src]

Return mutable vector of parsed Summary records.

Trait Implementations

impl Default for Summaries[src]

impl Debug for Summaries[src]

impl Display for Summaries[src]

impl Write for Summaries[src]

Auto Trait Implementations

Blanket Implementations

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> From<T> for T[src]

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]