pub enum SourceInfo {
V1(SourceInfoV1),
}Expand description
The representation of SRCINFO data.
Tracks all available versions of the file format.
Variants§
V1(SourceInfoV1)
The SRCINFO file format.
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 moreSource§impl Debug for SourceInfo
impl Debug for SourceInfo
Source§impl<'de> Deserialize<'de> for SourceInfo
impl<'de> Deserialize<'de> for SourceInfo
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 FromStr for SourceInfo
impl FromStr for SourceInfo
Source§fn from_str(s: &str) -> Result<Self, Self::Err>
fn from_str(s: &str) -> Result<Self, Self::Err>
Creates a SourceInfo from string slice s.
Calls SourceInfo::from_str_with_schema with schema set to None.
§Errors
Returns an error if
- a
SourceInfoSchemacannot be derived froms, - or the detected variant of
SourceInfocannot be constructed froms.
Source§impl MetadataFile<SourceInfoSchema> for SourceInfo
impl MetadataFile<SourceInfoSchema> for SourceInfo
Source§fn from_file_with_schema(
file: impl AsRef<Path>,
schema: Option<SourceInfoSchema>,
) -> Result<Self, Error>
fn from_file_with_schema( file: impl AsRef<Path>, schema: Option<SourceInfoSchema>, ) -> Result<Self, Error>
Creates a SourceInfo from file, optionally validated using a SourceInfoSchema.
Opens the file and defers to SourceInfo::from_reader_with_schema.
§Note
To automatically derive the SourceInfoSchema, use SourceInfo::from_file.
§Examples
use std::{fs::File, io::Write};
use alpm_common::{FileFormatSchema, MetadataFile};
use alpm_srcinfo::{SourceInfo, SourceInfoSchema};
use alpm_types::{SchemaVersion, semver_version::Version};
// Prepare a file with SRCINFO data
let srcinfo_file = tempfile::NamedTempFile::new()?;
let (file, srcinfo_data) = {
let srcinfo_data = r#"
pkgbase = example
pkgdesc = An example
arch = x86_64
pkgver = 0.1.0
pkgrel = 1
pkgname = example
"#;
let mut output = File::create(&srcinfo_file)?;
write!(output, "{}", srcinfo_data)?;
(srcinfo_file, srcinfo_data)
};
let srcinfo = SourceInfo::from_file_with_schema(
file.path().to_path_buf(),
Some(SourceInfoSchema::V1(SchemaVersion::new(Version::new(
1, 0, 0,
)))),
)?;§Errors
Returns an error if
- the
filecannot be opened for reading, - no variant of
SourceInfocan be constructed from the contents offile, - or
schemaisSomeand theSourceInfoSchemadoes not match the contents offile.
Source§fn from_reader_with_schema(
reader: impl Read,
schema: Option<SourceInfoSchema>,
) -> Result<Self, Error>
fn from_reader_with_schema( reader: impl Read, schema: Option<SourceInfoSchema>, ) -> Result<Self, Error>
Creates a SourceInfo from a reader, optionally validated using a
SourceInfoSchema.
Reads the reader to string and defers to SourceInfo::from_str_with_schema.
§Note
To automatically derive the SourceInfoSchema, use SourceInfo::from_reader.
§Examples
use std::{fs::File, io::Write};
use alpm_common::MetadataFile;
use alpm_srcinfo::{SourceInfo, SourceInfoSchema};
use alpm_types::{SchemaVersion, semver_version::Version};
let srcinfo_file = tempfile::NamedTempFile::new()?;
// Prepare a reader with SRCINFO data
let (reader, srcinfo_data) = {
let srcinfo_data = r#"
pkgbase = example
pkgdesc = An example
arch = x86_64
pkgver = 0.1.0
pkgrel = 1
pkgname = example
"#;
let mut output = File::create(&srcinfo_file)?;
write!(output, "{}", srcinfo_data)?;
(File::open(&srcinfo_file.path())?, srcinfo_data)
};
let srcinfo = SourceInfo::from_reader_with_schema(
reader,
Some(SourceInfoSchema::V1(SchemaVersion::new(Version::new(
1, 0, 0,
)))),
)?;§Errors
Returns an error if
- the
readercannot be read to string, - no variant of
SourceInfocan be constructed from the contents of thereader, - or
schemaisSomeand theSourceInfoSchemadoes not match the contents of thereader.
Source§fn from_str_with_schema(
s: &str,
schema: Option<SourceInfoSchema>,
) -> Result<Self, Error>
fn from_str_with_schema( s: &str, schema: Option<SourceInfoSchema>, ) -> Result<Self, Error>
Creates a SourceInfo from string slice, optionally validated using a
SourceInfoSchema.
If schema is None attempts to detect the SourceInfoSchema from s.
Attempts to create a SourceInfo variant that corresponds to the SourceInfoSchema.
§Note
To automatically derive the SourceInfoSchema, use SourceInfo::from_str.
§Examples
use std::{fs::File, io::Write};
use alpm_common::MetadataFile;
use alpm_srcinfo::{SourceInfo, SourceInfoSchema};
use alpm_types::{SchemaVersion, semver_version::Version};
let srcinfo_data = r#"
pkgbase = example
pkgdesc = An example
arch = x86_64
pkgver = 0.1.0
pkgrel = 1
pkgname = example
"#;
let srcinfo = SourceInfo::from_str_with_schema(
srcinfo_data,
Some(SourceInfoSchema::V1(SchemaVersion::new(Version::new(
1, 0, 0,
)))),
)?;§Errors
Returns an error if
schemaisSomeand the specified variant ofSourceInfocannot be constructed froms,schemaisNoneand- a
SourceInfoSchemacannot be derived froms, - or the detected variant of
SourceInfocannot be constructed froms.
- a