pub enum SourceInfoSchema {
    V1(SchemaVersion),
}Expand description
An enum tracking all available SRCINFO schemas.
The schema of a SRCINFO refers to the minimum required sections and keywords, as well as the complete set of available keywords in a specific version.
Variants§
V1(SchemaVersion)
Schema for the SRCINFO file format.
Trait Implementations§
Source§impl Clone for SourceInfoSchema
 
impl Clone for SourceInfoSchema
Source§fn clone(&self) -> SourceInfoSchema
 
fn clone(&self) -> SourceInfoSchema
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
 
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for SourceInfoSchema
 
impl Debug for SourceInfoSchema
Source§impl Default for SourceInfoSchema
 
impl Default for SourceInfoSchema
Source§fn default() -> Self
 
fn default() -> Self
Returns the default SourceInfoSchema variant (SourceInfoSchema::V1).
Source§impl Display for SourceInfoSchema
 
impl Display for SourceInfoSchema
Source§impl FileFormatSchema for SourceInfoSchema
 
impl FileFormatSchema for SourceInfoSchema
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 SourceInfoSchema from a SRCINFO file.
Opens the file and defers to SourceInfoSchema::derive_from_reader.
§Errors
Returns an error if
- opening 
filefor reading fails - or deriving a 
SourceInfoSchemafrom 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 SourceInfoSchema from SRCINFO data in a reader.
Reads the reader to string and defers to SourceInfoSchema::derive_from_str.
§Errors
Returns an error if
- reading a 
Stringfromreaderfails - or deriving a 
SourceInfoSchemafrom the contents ofreaderfails. 
Source§fn derive_from_str(s: &str) -> Result<SourceInfoSchema, Error>
 
fn derive_from_str(s: &str) -> Result<SourceInfoSchema, Error>
Derives a SourceInfoSchema from a string slice containing SRCINFO data.
Since the SRCINFO format is only covered by a single version and it not carrying any
version information, this function checks whether s contains at least the sections
pkgbase and pkgname and the keywords pkgver and pkgrel.
§Examples
use alpm_common::FileFormatSchema;
use alpm_srcinfo::SourceInfoSchema;
use alpm_types::{SchemaVersion, semver_version::Version};
let srcinfo_data = r#"
pkgbase = example
    pkgdesc = An example
    pkgver = 0.1.0
    pkgrel = 1
pkgname = example
"#;§Errors
Returns an error if s cannot be parsed.
Source§impl FromStr for SourceInfoSchema
 
impl FromStr for SourceInfoSchema
Source§fn from_str(s: &str) -> Result<SourceInfoSchema, Self::Err>
 
fn from_str(s: &str) -> Result<SourceInfoSchema, Self::Err>
Creates a SourceInfoSchema from string slice s.
Relies on SchemaVersion::from_str to create a corresponding SourceInfoSchema from
s.
§Errors
Returns an error if
- no 
SchemaVersioncan be created froms, - or the conversion from 
SchemaVersiontoSourceInfoSchemafails. 
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 
 
Source§impl PartialEq for SourceInfoSchema
 
impl PartialEq for SourceInfoSchema
Source§impl TryFrom<SchemaVersion> for SourceInfoSchema
 
impl TryFrom<SchemaVersion> for SourceInfoSchema
Source§fn try_from(value: SchemaVersion) -> Result<Self, Self::Error>
 
fn try_from(value: SchemaVersion) -> Result<Self, Self::Error>
Converts a SchemaVersion to a SourceInfoSchema.
§Errors
Returns an error if the SchemaVersion’s inner Version does not provide a major
version that corresponds to a SourceInfoSchema variant.