pub struct SourceInfoV1 {
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
The information of the pkgbase
section.
packages: Vec<Package>
The information of the pkgname
sections.
Implementations§
Source§impl SourceInfoV1
impl SourceInfoV1
Sourcepub fn as_srcinfo(&self) -> String
pub fn as_srcinfo(&self) -> String
Returns the SRCINFO representation.
use std::{env::var, path::PathBuf};
use alpm_srcinfo::SourceInfoV1;
const TEST_FILE: &str = include_str!("../../../tests/unit_test_files/normal.srcinfo");
// Read a .SRCINFO file and bring it into the `SourceInfoV1` representation.
let source_info = SourceInfoV1::from_string(TEST_FILE)?;
// Convert the `SourceInfoV1` back into it's alpm `.SRCINFO` format.
println!("{}", source_info.as_srcinfo());
Sourcepub fn from_file(path: &Path) -> Result<SourceInfoV1, Error>
pub fn from_file(path: &Path) -> Result<SourceInfoV1, Error>
Reads the file at the specified path and converts it into a SourceInfoV1
struct.
§Errors
Returns an Error
if the file cannot be read or parsed.
Sourcepub fn from_pkgbuild(pkgbuild_path: &Path) -> Result<SourceInfoV1, Error>
pub fn from_pkgbuild(pkgbuild_path: &Path) -> Result<SourceInfoV1, Error>
Creates a SourceInfoV1
from a PKGBUILD
file.
§Errors
Returns an error if
- The
PKGBUILD
cannot be read. - a required field is not set,
- a
package
functions exists, but does not correspond to a declared alpm-split-package, - a
package
function without an alpm-package-name suffix exists in an alpm-split-package setup, - a value cannot be turned into its
alpm_types
equivalent, - multiple values exist for a field that only accepts a singular value,
- an alpm-architecture is duplicated,
- an alpm-architecture is cleared in
package
function, - or an alpm-architecture suffix is set on a keyword that does not support it.
Sourcepub fn from_string(content: &str) -> Result<SourceInfoV1, Error>
pub fn from_string(content: &str) -> Result<SourceInfoV1, Error>
Parses a SRCINFO file’s content into a SourceInfoV1
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. - An
Error
is returned if the parsed data is incomplete or otherwise invalid.
use alpm_srcinfo::SourceInfoV1;
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 errors if the file cannot be parsed, is missing data or contains invalid data.
let source_info = SourceInfoV1::from_string(source_info_data)?;
Sourcepub fn from_raw(content: SourceInfoContent) -> Result<SourceInfoV1, Error>
pub fn from_raw(content: SourceInfoContent) -> Result<SourceInfoV1, Error>
Reads raw SourceInfoContent
from a first parsing step and converts it into a
SourceInfoV1
.
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, SourceInfoV1};
use alpm_types::{Architecture, Name, PackageDescription, 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 errors if the file cannot be parsed, is missing data or contains invalid data.
let source_info = SourceInfoV1::from_string(source_info_data)?;
/// 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(PackageDescription::new("Example split package"))
);
let example_other = packages.next().unwrap();
assert_eq!(
example_other.description,
Some(PackageDescription::new("The other example split package"))
);
Trait Implementations§
Source§impl Clone for SourceInfoV1
impl Clone for SourceInfoV1
Source§fn clone(&self) -> SourceInfoV1
fn clone(&self) -> SourceInfoV1
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl Debug for SourceInfoV1
impl Debug for SourceInfoV1
Source§impl<'de> Deserialize<'de> for SourceInfoV1
impl<'de> Deserialize<'de> for SourceInfoV1
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl PartialEq for SourceInfoV1
impl PartialEq for SourceInfoV1
Source§impl Serialize for SourceInfoV1
impl Serialize for SourceInfoV1
Source§impl TryFrom<BridgeOutput> for SourceInfoV1
impl TryFrom<BridgeOutput> for SourceInfoV1
Source§fn try_from(value: BridgeOutput) -> Result<Self, Self::Error>
fn try_from(value: BridgeOutput) -> Result<Self, Self::Error>
Creates a SourceInfoV1
from a BridgeOutput
.
See errors and documentation in SourceInfoV1::from_pkgbuild