pub struct SourceInfo {
pub base: PackageBase,
pub packages: Vec<Package>,
}
Expand description
The representation of SRCINFO data.
Provides access to a PackageBase
which tracks all data in a pkgbase
section and a list of
Package
instances that provide the accumulated data of all pkgname
sections.
This is the entry point for parsing SRCINFO files. Once created,
Self::packages_for_architecture
can be used to create usable MergedPackage
s.
Fields§
§base: PackageBase
§packages: Vec<Package>
Implementations§
Source§impl SourceInfo
impl SourceInfo
Sourcepub fn from_file(path: &Path) -> Result<SourceInfoResult, Error>
pub fn from_file(path: &Path) -> Result<SourceInfoResult, Error>
Reads the file at the specified path and converts it into a SourceInfo
struct.
§Errors
Returns an Error
if the file cannot be read or parsed.
Returns an error array with potentially un/-recoverable errors, this needs to be explicitly
handled by the user.
Sourcepub fn from_string(content: &str) -> Result<SourceInfoResult, Error>
pub fn from_string(content: &str) -> Result<SourceInfoResult, Error>
Parses a SRCINFO file’s content into a SourceInfo
struct.
§Error
This function returns two types of errors.
- An
Error
is returned if the input is, for example, invalid UTF-8 or if the input SRCINFO file couldn’t be parsed due to invalid syntax. - If the parsing was successful, a
SourceInfoResult
is returned, which wraps a possibly invalidSourceInfo
and possibleSourceInfoErrors
.SourceInfoErrors
contains all errors and lint/deprecation warnings that’re encountered while interpreting the SRCINFO file.
use alpm_srcinfo::SourceInfo;
use alpm_types::{Architecture, Name, PackageRelation};
let source_info_data = r#"
pkgbase = example
pkgver = 1.0.0
epoch = 1
pkgrel = 1
pkgdesc = A project that does something
url = https://example.org/
arch = x86_64
depends = glibc
optdepends = python: for special-python-script.py
makedepends = cmake
checkdepends = extra-test-tool
pkgname = example
depends = glibc
depends = gcc-libs
"#;
// Parse the file. This might already error if the file cannot be parsed on a low level.
let source_info_result = SourceInfo::from_string(source_info_data)?;
// Make sure there're no other unrecoverable errors.
let source_info = source_info_result.source_info()?;
Sourcepub fn from_raw(
content: SourceInfoContent,
) -> (SourceInfo, Vec<SourceInfoError>)
pub fn from_raw( content: SourceInfoContent, ) -> (SourceInfo, Vec<SourceInfoError>)
Reads raw SourceInfoContent
from a first parsing step and converts it into a
SourceInfo
.
Instead of a Result
this function returns a tuple of SourceInfo
and a vector of
SourceInfoError
s. The caller is expected to handle the vector of SourceInfoError
s,
which may only consist of linting errors that can be ignored.
Sourcepub fn packages_for_architecture(
&self,
architecture: Architecture,
) -> MergedPackagesIterator<'_> ⓘ
pub fn packages_for_architecture( &self, architecture: Architecture, ) -> MergedPackagesIterator<'_> ⓘ
Get an iterator over all packages
use alpm_srcinfo::{MergedPackage, SourceInfo};
use alpm_types::{Architecture, Name, PackageRelation};
let source_info_data = r#"
pkgbase = example
pkgver = 1.0.0
epoch = 1
pkgrel = 1
arch = x86_64
pkgname = example
pkgdesc = Example split package
pkgname = example_other
pkgdesc = The other example split package
"#;
// Parse the file. This might already error if the file cannot be parsed on a low level.
let result = SourceInfo::from_string(source_info_data)?;
// Make sure there're aren't unrecoverable logic errors, such as missing values.
let source_info = result.source_info()?;
/// Get all merged package representations for the x86_64 architecture.
let mut packages = source_info.packages_for_architecture(Architecture::X86_64);
let example = packages.next().unwrap();
assert_eq!(
example.description,
Some("Example split package".to_string())
);
let example_other = packages.next().unwrap();
assert_eq!(
example_other.description,
Some("The other example split package".to_string())
);
Trait Implementations§
Source§impl Clone for SourceInfo
impl Clone for SourceInfo
Source§fn clone(&self) -> SourceInfo
fn clone(&self) -> SourceInfo
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more