pub enum BuildInfo {
V1(BuildInfoV1),
V2(BuildInfoV2),
}Expand description
A representation of the BUILDINFO file format.
Tracks all available variants of the file format.
Variants§
Trait Implementations§
Source§impl FromStr for BuildInfo
impl FromStr for BuildInfo
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