pub enum BuildInfoSchema {
V1(SchemaVersion),
V2(SchemaVersion),
}Expand description
An enum describing all valid BUILDINFO schemas
Variants§
V1(SchemaVersion)
Schema for the BUILDINFOv1 file format.
V2(SchemaVersion)
Schema for the BUILDINFOv2 file format.
Trait Implementations§
Source§impl Clone for BuildInfoSchema
impl Clone for BuildInfoSchema
Source§fn clone(&self) -> BuildInfoSchema
fn clone(&self) -> BuildInfoSchema
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for BuildInfoSchema
impl Debug for BuildInfoSchema
Source§impl Default for BuildInfoSchema
impl Default for BuildInfoSchema
Source§fn default() -> Self
fn default() -> Self
Returns the default BuildInfoSchema variant (BuildInfoSchema::V2)
Source§impl Display for BuildInfoSchema
impl Display for BuildInfoSchema
Source§impl FileFormatSchema for BuildInfoSchema
impl FileFormatSchema for BuildInfoSchema
Source§fn inner(&self) -> &SchemaVersion
fn inner(&self) -> &SchemaVersion
Returns the schema version
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 BuildInfoSchema from a BUILDINFO file.
Opens the file and defers to BuildInfoSchema::derive_from_reader.
§Errors
Returns an error if
- opening
filefor reading fails - or deriving a
BuildInfoSchemafrom 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 BuildInfoSchema from BUILDINFO data in a reader.
Reads the reader to string and defers to BuildInfoSchema::derive_from_str.
§Errors
Returns an error if
- reading a
Stringfromreaderfails - or deriving a
BuildInfoSchemafrom the contents ofreaderfails.
Source§fn derive_from_str(s: &str) -> Result<BuildInfoSchema, Error>
fn derive_from_str(s: &str) -> Result<BuildInfoSchema, Error>
Derives a BuildInfoSchema from a string slice containing BUILDINFO data.
Relies on the format keyword and its assigned value in the BUILDINFO data to derive a
corresponding BuildInfoSchema.
§Examples
use alpm_buildinfo::BuildInfoSchema;
use alpm_common::FileFormatSchema;
use alpm_types::{SchemaVersion, semver_version::Version};
let buildinfo_v2 = r#"format = 2
builddate = 1
builddir = /build
startdir = /startdir
buildtool = devtools
buildtoolver = 1:1.2.1-1-any
buildenv = ccache
installed = bar-1.2.3-1-any
options = lto
packager = Foobar McFooface <foobar@mcfooface.org>
pkgarch = any
pkgbase = foo
pkgbuild_sha256sum = b5bb9d8014a0f9b1d61e21e796d78dccdf1352f23cd32812f4850b878ae4944c
pkgname = foo
pkgver = 1:1.0.0-1"#;
assert_eq!(
BuildInfoSchema::V2(SchemaVersion::new(Version::new(2, 0, 0))),
BuildInfoSchema::derive_from_str(buildinfo_v2)?
);
let buildinfo_v1 = r#"format = 1
builddate = 1
builddir = /build
startdir = /startdir
buildenv = ccache
installed = bar-1.2.3-1-any
options = lto
packager = Foobar McFooface <foobar@mcfooface.org>
pkgarch = any
pkgbase = foo
pkgbuild_sha256sum = b5bb9d8014a0f9b1d61e21e796d78dccdf1352f23cd32812f4850b878ae4944c
pkgname = foo
pkgver = 1:1.0.0-1"#;
assert_eq!(
BuildInfoSchema::V1(SchemaVersion::new(Version::new(1, 0, 0))),
BuildInfoSchema::derive_from_str(buildinfo_v1)?
);§Errors
Returns an error if
- the
formatfield is missing froms - or deriving a
BuildInfoSchemafromformatfield fails.
Source§impl FromStr for BuildInfoSchema
impl FromStr for BuildInfoSchema
Source§fn from_str(s: &str) -> Result<BuildInfoSchema, Self::Err>
fn from_str(s: &str) -> Result<BuildInfoSchema, Self::Err>
Creates a BuildInfoSchema from string slice s.
Relies on SchemaVersion::from_str to create a corresponding BuildInfoSchema from
s.
§Errors
Returns an error if
- no
SchemaVersioncan be created froms, - or the conversion from
SchemaVersiontoBuildInfoSchemafails.
Source§impl MetadataFile<BuildInfoSchema> for BuildInfo
impl MetadataFile<BuildInfoSchema> for BuildInfo
Source§fn from_file_with_schema(
file: impl AsRef<Path>,
schema: Option<BuildInfoSchema>,
) -> Result<Self, Error>
fn from_file_with_schema( file: impl AsRef<Path>, schema: Option<BuildInfoSchema>, ) -> Result<Self, Error>
Creates a BuildInfo from file, optionally validated using a BuildInfoSchema.
Opens the file and defers to BuildInfo::from_reader_with_schema.
§Note
To automatically derive the BuildInfoSchema, use BuildInfo::from_file.
§Examples
use std::{fs::File, io::Write};
use alpm_buildinfo::{BuildInfo, BuildInfoSchema};
use alpm_common::{FileFormatSchema, MetadataFile};
use alpm_types::{SchemaVersion, semver_version::Version};
// Prepare a file with BUILDINFO data
let (file, buildinfo_data) = {
let buildinfo_data = r#"format = 2
pkgname = foo
pkgbase = foo
pkgver = 1:1.0.0-1
pkgarch = any
pkgbuild_sha256sum = b5bb9d8014a0f9b1d61e21e796d78dccdf1352f23cd32812f4850b878ae4944c
packager = Foobar McFooface <foobar@mcfooface.org>
builddate = 1
builddir = /build
startdir = /startdir/
buildtool = devtools
buildtoolver = 1:1.2.1-1-any
buildenv = ccache
options = lto
installed = bar-1.2.3-1-any
"#;
let file = tempfile::NamedTempFile::new()?;
let mut output = File::create(&file)?;
write!(output, "{}", buildinfo_data)?;
(file, buildinfo_data)
};
let buildinfo = BuildInfo::from_file_with_schema(
file.path(),
Some(BuildInfoSchema::V2(SchemaVersion::new(Version::new(
2, 0, 0,
)))),
)?;
assert_eq!(buildinfo.to_string(), buildinfo_data);§Errors
Returns an error if
- the
filecannot be opened for reading, - no variant of
BuildInfocan be constructed from the contents offile, - or
schemaisSomeand theBuildInfoSchemadoes not match the contents offile.
Source§fn from_reader_with_schema(
reader: impl Read,
schema: Option<BuildInfoSchema>,
) -> Result<Self, Error>
fn from_reader_with_schema( reader: impl Read, schema: Option<BuildInfoSchema>, ) -> Result<Self, Error>
Creates a BuildInfo from a reader, optionally validated using a BuildInfoSchema.
Reads the reader to string and defers to BuildInfo::from_str_with_schema.
§Note
To automatically derive the BuildInfoSchema, use BuildInfo::from_reader.
§Examples
use std::{fs::File, io::Write};
use alpm_buildinfo::{BuildInfo, BuildInfoSchema};
use alpm_common::MetadataFile;
use alpm_types::{SchemaVersion, semver_version::Version};
// Prepare a reader with BUILDINFO data
let (reader, buildinfo_data) = {
let buildinfo_data = r#"format = 2
pkgname = foo
pkgbase = foo
pkgver = 1:1.0.0-1
pkgarch = any
pkgbuild_sha256sum = b5bb9d8014a0f9b1d61e21e796d78dccdf1352f23cd32812f4850b878ae4944c
packager = Foobar McFooface <foobar@mcfooface.org>
builddate = 1
builddir = /build
startdir = /startdir/
buildtool = devtools
buildtoolver = 1:1.2.1-1-any
buildenv = ccache
options = lto
installed = bar-1.2.3-1-any
"#;
let buildinfo_file = tempfile::NamedTempFile::new()?;
let mut output = File::create(&buildinfo_file)?;
write!(output, "{}", buildinfo_data)?;
(File::open(&buildinfo_file.path())?, buildinfo_data)
};
let buildinfo = BuildInfo::from_reader_with_schema(
reader,
Some(BuildInfoSchema::V2(SchemaVersion::new(Version::new(
2, 0, 0,
)))),
)?;
assert_eq!(buildinfo.to_string(), buildinfo_data);§Errors
Returns an error if
- the
readercannot be read to string, - no variant of
BuildInfocan be constructed from the contents of thereader, - or
schemaisSomeand theBuildInfoSchemadoes not match the contents of thereader.
Source§fn from_str_with_schema(
s: &str,
schema: Option<BuildInfoSchema>,
) -> Result<Self, Error>
fn from_str_with_schema( s: &str, schema: Option<BuildInfoSchema>, ) -> Result<Self, Error>
Creates a BuildInfo from string slice, optionally validated using a BuildInfoSchema.
If schema is None attempts to detect the BuildInfoSchema from s.
Attempts to create a BuildInfo variant that corresponds to the BuildInfoSchema.
§Note
To automatically derive the BuildInfoSchema, use BuildInfo::from_str.
§Examples
use std::{fs::File, io::Write};
use alpm_buildinfo::{BuildInfo, BuildInfoSchema};
use alpm_common::MetadataFile;
use alpm_types::{SchemaVersion, semver_version::Version};
let buildinfo_v2_data = r#"format = 2
pkgname = foo
pkgbase = foo
pkgver = 1:1.0.0-1
pkgarch = any
pkgbuild_sha256sum = b5bb9d8014a0f9b1d61e21e796d78dccdf1352f23cd32812f4850b878ae4944c
packager = Foobar McFooface <foobar@mcfooface.org>
builddate = 1
builddir = /build
startdir = /startdir/
buildtool = devtools
buildtoolver = 1:1.2.1-1-any
buildenv = ccache
options = lto
installed = bar-1.2.3-1-any
"#;
let buildinfo_v2 = BuildInfo::from_str_with_schema(
buildinfo_v2_data,
Some(BuildInfoSchema::V2(SchemaVersion::new(Version::new(
2, 0, 0,
)))),
)?;
assert_eq!(buildinfo_v2.to_string(), buildinfo_v2_data);
let buildinfo_v1_data = r#"format = 1
pkgname = foo
pkgbase = foo
pkgver = 1:1.0.0-1
pkgarch = any
pkgbuild_sha256sum = b5bb9d8014a0f9b1d61e21e796d78dccdf1352f23cd32812f4850b878ae4944c
packager = Foobar McFooface <foobar@mcfooface.org>
builddate = 1
builddir = /build
buildenv = ccache
options = lto
installed = bar-1.2.3-1-any
"#;
let buildinfo_v1 = BuildInfo::from_str_with_schema(
buildinfo_v1_data,
Some(BuildInfoSchema::V1(SchemaVersion::new(Version::new(
1, 0, 0,
)))),
)?;
assert_eq!(buildinfo_v1.to_string(), buildinfo_v1_data);§Errors
Returns an error if
schemaisSomeand the specified variant ofBuildInfocannot be constructed froms,schemaisNoneand- a
BuildInfoSchemacannot be derived froms, - or the detected variant of
BuildInfocannot be constructed froms.
- a
Source§impl PartialEq for BuildInfoSchema
impl PartialEq for BuildInfoSchema
Source§impl TryFrom<SchemaVersion> for BuildInfoSchema
impl TryFrom<SchemaVersion> for BuildInfoSchema
Source§fn try_from(value: SchemaVersion) -> Result<Self, Self::Error>
fn try_from(value: SchemaVersion) -> Result<Self, Self::Error>
Converts a SchemaVersion to a BuildInfoSchema.
§Errors
Returns an error if the SchemaVersion’s inner Version does not provide a major
version that corresponds to a BuildInfoSchema variant.