pub enum PackageInfoSchema {
V1(SchemaVersion),
V2(SchemaVersion),
}Expand description
An enum tracking all available PKGINFO schemas.
The schema of a PKGINFO refers to its available fields in a specific version.
Variants§
V1(SchemaVersion)
Schema for the PKGINFOv1 file format.
V2(SchemaVersion)
Schema for the PKGINFOv2 file format.
Trait Implementations§
Source§impl Clone for PackageInfoSchema
impl Clone for PackageInfoSchema
Source§fn clone(&self) -> PackageInfoSchema
fn clone(&self) -> PackageInfoSchema
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for PackageInfoSchema
impl Debug for PackageInfoSchema
Source§impl Default for PackageInfoSchema
impl Default for PackageInfoSchema
Source§fn default() -> Self
fn default() -> Self
Returns the default PackageInfoSchema variant (PackageInfoSchema::V2).
Source§impl Display for PackageInfoSchema
impl Display for PackageInfoSchema
Source§impl FileFormatSchema for PackageInfoSchema
impl FileFormatSchema for PackageInfoSchema
Source§fn inner(&self) -> &SchemaVersion
fn inner(&self) -> &SchemaVersion
Returns a reference to the inner SchemaVersion.
Source§fn derive_from_file(file: impl AsRef<Path>) -> Result<Self, Error>where
Self: Sized,
fn derive_from_file(file: impl AsRef<Path>) -> Result<Self, Error>where
Self: Sized,
Derives a PackageInfoSchema from a PKGINFO file.
Opens the file and defers to PackageInfoSchema::derive_from_reader.
§Errors
Returns an error if
- opening
filefor reading fails - or deriving a
PackageInfoSchemafrom the contents offilefails.
Source§fn derive_from_reader(reader: impl Read) -> Result<Self, Error>where
Self: Sized,
fn derive_from_reader(reader: impl Read) -> Result<Self, Error>where
Self: Sized,
Derives a PackageInfoSchema from PKGINFO data in a reader.
Reads the reader to string and defers to PackageInfoSchema::derive_from_str.
§Errors
Returns an error if
- reading a
Stringfromreaderfails - or deriving a
PackageInfoSchemafrom the contents ofreaderfails.
Source§fn derive_from_str(s: &str) -> Result<PackageInfoSchema, Error>
fn derive_from_str(s: &str) -> Result<PackageInfoSchema, Error>
Derives a PackageInfoSchema from a string slice containing PKGINFO data.
Since the PKGINFO format does not carry any version information, this function looks for the
first xdata field (if any) to determine whether the input may be PKGINFOv2.
If no xdata field is found, PKGINFOv1 is assumed.
§Examples
use alpm_common::FileFormatSchema;
use alpm_pkginfo::PackageInfoSchema;
use alpm_types::{SchemaVersion, semver_version::Version};
let pkginfo_v2 = r#"
pkgname = example
pkgbase = example
pkgver = 1:1.0.0-1
pkgdesc = A project that does something
url = https://example.org/
builddate = 1729181726
packager = John Doe <john@example.org>
size = 181849963
arch = any
xdata = pkgtype=pkg
"#;
assert_eq!(
PackageInfoSchema::V2(SchemaVersion::new(Version::new(2, 0, 0))),
PackageInfoSchema::derive_from_str(pkginfo_v2)?
);
let pkginfo_v1 = r#"
pkgname = example
pkgbase = example
pkgver = 1:1.0.0-1
pkgdesc = A project that does something
url = https://example.org/
builddate = 1729181726
packager = John Doe <john@example.org>
size = 181849963
arch = any
"#;
assert_eq!(
PackageInfoSchema::V1(SchemaVersion::new(Version::new(1, 0, 0))),
PackageInfoSchema::derive_from_str(pkginfo_v1)?
);§Errors
Returns an error if
- the first
xdatakeyword is assigned an empty string, - or the first
xdatakeyword does not assign “pkgtype”.
Source§impl FromStr for PackageInfoSchema
impl FromStr for PackageInfoSchema
Source§fn from_str(s: &str) -> Result<PackageInfoSchema, Self::Err>
fn from_str(s: &str) -> Result<PackageInfoSchema, Self::Err>
Creates a PackageInfoSchema from string slice s.
Relies on SchemaVersion::from_str to create a corresponding PackageInfoSchema from
s.
§Errors
Returns an error if
- no
SchemaVersioncan be created froms, - or the conversion from
SchemaVersiontoPackageInfoSchemafails.
Source§impl MetadataFile<PackageInfoSchema> for PackageInfo
impl MetadataFile<PackageInfoSchema> for PackageInfo
Source§fn from_file_with_schema(
file: impl AsRef<Path>,
schema: Option<PackageInfoSchema>,
) -> Result<Self, Error>
fn from_file_with_schema( file: impl AsRef<Path>, schema: Option<PackageInfoSchema>, ) -> Result<Self, Error>
Creates a PackageInfo from file, optionally validated using a PackageInfoSchema.
Opens the file and defers to PackageInfo::from_reader_with_schema.
§Note
To automatically derive the PackageInfoSchema, use PackageInfo::from_file.
§Examples
use std::{fs::File, io::Write};
use alpm_common::{FileFormatSchema, MetadataFile};
use alpm_pkginfo::{PackageInfo, PackageInfoSchema};
use alpm_types::{SchemaVersion, semver_version::Version};
// Prepare a file with PKGINFO data
let (file, pkginfo_data) = {
let pkginfo_data = r#"pkgname = example
pkgbase = example
xdata = pkgtype=pkg
pkgver = 1:1.0.0-1
pkgdesc = A project that does something
url = https://example.org/
builddate = 1729181726
packager = John Doe <john@example.org>
size = 181849963
arch = any
"#;
let pkginfo_file = tempfile::NamedTempFile::new()?;
let mut output = File::create(&pkginfo_file)?;
write!(output, "{}", pkginfo_data)?;
(pkginfo_file, pkginfo_data)
};
let pkginfo = PackageInfo::from_file_with_schema(
file.path().to_path_buf(),
Some(PackageInfoSchema::V2(SchemaVersion::new(Version::new(
2, 0, 0,
)))),
)?;
assert_eq!(pkginfo.to_string(), pkginfo_data);§Errors
Returns an error if
- the
filecannot be opened for reading, - no variant of
PackageInfocan be constructed from the contents offile, - or
schemaisSomeand thePackageInfoSchemadoes not match the contents offile.
Source§fn from_reader_with_schema(
reader: impl Read,
schema: Option<PackageInfoSchema>,
) -> Result<Self, Error>
fn from_reader_with_schema( reader: impl Read, schema: Option<PackageInfoSchema>, ) -> Result<Self, Error>
Creates a PackageInfo from a reader, optionally validated using a
PackageInfoSchema.
Reads the reader to string and defers to PackageInfo::from_str_with_schema.
§Note
To automatically derive the PackageInfoSchema, use PackageInfo::from_reader.
§Examples
use std::{fs::File, io::Write};
use alpm_common::MetadataFile;
use alpm_pkginfo::{PackageInfo, PackageInfoSchema};
use alpm_types::{SchemaVersion, semver_version::Version};
// Prepare a reader with PKGINFO data
let (reader, pkginfo_data) = {
let pkginfo_data = r#"pkgname = example
pkgbase = example
xdata = pkgtype=pkg
pkgver = 1:1.0.0-1
pkgdesc = A project that does something
url = https://example.org/
builddate = 1729181726
packager = John Doe <john@example.org>
size = 181849963
arch = any
"#;
let pkginfo_file = tempfile::NamedTempFile::new()?;
let mut output = File::create(&pkginfo_file)?;
write!(output, "{}", pkginfo_data)?;
(File::open(&pkginfo_file.path())?, pkginfo_data)
};
let pkginfo = PackageInfo::from_reader_with_schema(
reader,
Some(PackageInfoSchema::V2(SchemaVersion::new(Version::new(
2, 0, 0,
)))),
)?;
assert_eq!(pkginfo.to_string(), pkginfo_data);§Errors
Returns an error if
- the
readercannot be read to string, - no variant of
PackageInfocan be constructed from the contents of thereader, - or
schemaisSomeand thePackageInfoSchemadoes not match the contents of thereader.
Source§fn from_str_with_schema(
s: &str,
schema: Option<PackageInfoSchema>,
) -> Result<Self, Error>
fn from_str_with_schema( s: &str, schema: Option<PackageInfoSchema>, ) -> Result<Self, Error>
Creates a PackageInfo from string slice, optionally validated using a
PackageInfoSchema.
If schema is None attempts to detect the PackageInfoSchema from s.
Attempts to create a PackageInfo variant that corresponds to the PackageInfoSchema.
§Note
To automatically derive the PackageInfoSchema, use PackageInfo::from_str.
§Examples
use std::{fs::File, io::Write};
use alpm_common::MetadataFile;
use alpm_pkginfo::{PackageInfo, PackageInfoSchema};
use alpm_types::{SchemaVersion, semver_version::Version};
let pkginfo_v2_data = r#"pkgname = example
pkgbase = example
xdata = pkgtype=pkg
pkgver = 1:1.0.0-1
pkgdesc = A project that does something
url = https://example.org/
builddate = 1729181726
packager = John Doe <john@example.org>
size = 181849963
arch = any
"#;
let pkginfo_v2 = PackageInfo::from_str_with_schema(
pkginfo_v2_data,
Some(PackageInfoSchema::V2(SchemaVersion::new(Version::new(
2, 0, 0,
)))),
)?;
assert_eq!(pkginfo_v2.to_string(), pkginfo_v2_data);
let pkginfo_v1_data = r#"pkgname = example
pkgbase = example
pkgver = 1:1.0.0-1
pkgdesc = A project that does something
url = https://example.org/
builddate = 1729181726
packager = John Doe <john@example.org>
size = 181849963
arch = any
"#;
let pkginfo_v1 = PackageInfo::from_str_with_schema(
pkginfo_v1_data,
Some(PackageInfoSchema::V1(SchemaVersion::new(Version::new(
1, 0, 0,
)))),
)?;
assert_eq!(pkginfo_v1.to_string(), pkginfo_v1_data);§Errors
Returns an error if
schemaisSomeand the specified variant ofPackageInfocannot be constructed froms,schemaisNoneand- a
PackageInfoSchemacannot be derived froms, - or the detected variant of
PackageInfocannot be constructed froms.
- a
Source§impl PartialEq for PackageInfoSchema
impl PartialEq for PackageInfoSchema
Source§impl TryFrom<SchemaVersion> for PackageInfoSchema
impl TryFrom<SchemaVersion> for PackageInfoSchema
Source§fn try_from(value: SchemaVersion) -> Result<Self, Self::Error>
fn try_from(value: SchemaVersion) -> Result<Self, Self::Error>
Converts a SchemaVersion to a PackageInfoSchema.
§Errors
Returns an error if the SchemaVersion’s inner Version does not provide a major
version that corresponds to a PackageInfoSchema variant.