pub enum DbDescSchema {
V1(SchemaVersion),
V2(SchemaVersion),
}Expand description
An enum describing all valid alpm-db-desc schemas.
Each variant corresponds to a specific revision of the specification.
Variants§
V1(SchemaVersion)
Schema for the alpm-db-descv1 file format.
V2(SchemaVersion)
Schema for the alpm-db-descv2 file format.
Trait Implementations§
Source§impl AsRef<SchemaVersion> for DbDescSchema
impl AsRef<SchemaVersion> for DbDescSchema
Source§fn as_ref(&self) -> &SchemaVersion
fn as_ref(&self) -> &SchemaVersion
Returns a reference to the targeted SchemaVersion.
Source§impl Clone for DbDescSchema
impl Clone for DbDescSchema
Source§impl Debug for DbDescSchema
impl Debug for DbDescSchema
Source§impl Default for DbDescSchema
impl Default for DbDescSchema
Source§fn default() -> Self
fn default() -> Self
Returns the default schema variant (DbDescSchema::V2).
Source§impl Display for DbDescSchema
impl Display for DbDescSchema
impl Eq for DbDescSchema
Source§impl FileFormatSchema for DbDescSchema
impl FileFormatSchema for DbDescSchema
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 DbDescSchema from an alpm-db-desc file on disk.
Opens the file and defers to DbDescSchema::derive_from_reader.
§Errors
Returns an error if:
- the file cannot be opened for reading,
- or deriving a
DbDescSchemafrom its contents fails.
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 DbDescSchema from alpm-db-desc data in a reader.
Reads the reader to a string and defers to DbDescSchema::derive_from_str.
§Errors
Returns an error if:
- reading from
readerfails, - or deriving a
DbDescSchemafrom its contents fails.
Source§fn derive_from_str(s: &str) -> Result<DbDescSchema, Error>
fn derive_from_str(s: &str) -> Result<DbDescSchema, Error>
Derives a DbDescSchema from a string slice containing alpm-db-desc data.
The parser uses a simple heuristic:
- v1 → no
%XDATA%section present - v2 →
%XDATA%section present
This approach avoids relying on explicit version metadata, as the DB desc format itself is not self-describing.
§Examples
use alpm_common::FileFormatSchema;
use alpm_db::desc::DbDescSchema;
use alpm_types::{SchemaVersion, semver_version::Version};
let v1_data = r#"%NAME%
foo
%VERSION%
1.0.0-1
"#;
assert_eq!(
DbDescSchema::V1(SchemaVersion::new(Version::new(1, 0, 0))),
DbDescSchema::derive_from_str(v1_data)?
);
let v2_data = r#"%NAME%
foo
%VERSION%
1.0.0-1
%XDATA%
pkgtype=pkg
"#;
assert_eq!(
DbDescSchema::V2(SchemaVersion::new(Version::new(2, 0, 0))),
DbDescSchema::derive_from_str(v2_data)?
);§Errors
Returns an error only if internal conversion or string handling fails.
Source§impl FromStr for DbDescSchema
impl FromStr for DbDescSchema
Source§fn from_str(s: &str) -> Result<DbDescSchema, Self::Err>
fn from_str(s: &str) -> Result<DbDescSchema, Self::Err>
Parses a DbDescSchema from a version string.
§Errors
Returns an error if:
- the input string is not a valid version,
- or the version does not correspond to a known schema variant.
Source§impl MetadataFile<DbDescSchema> for DbDescFile
impl MetadataFile<DbDescSchema> for DbDescFile
Source§fn from_file_with_schema(
file: impl AsRef<Path>,
schema: Option<DbDescSchema>,
) -> Result<Self, Error>
fn from_file_with_schema( file: impl AsRef<Path>, schema: Option<DbDescSchema>, ) -> Result<Self, Error>
Creates a DbDescFile from a file on disk, optionally validated using a DbDescSchema.
Opens the file and defers to DbDescFile::from_reader_with_schema.
§Examples
use std::{fs::File, io::Write};
use alpm_common::{FileFormatSchema, MetadataFile};
use alpm_db::desc::{DbDescFile, DbDescSchema};
use alpm_types::{SchemaVersion, semver_version::Version};
// Prepare a file with DB desc data (v1)
let (file, desc_data) = {
let desc_data = r#"%NAME%
foo
%VERSION%
1.0.0-1
%BASE%
foo
%DESC%
An example package
%URL%
https://example.org/
%ARCH%
x86_64
%BUILDDATE%
1733737242
%INSTALLDATE%
1733737243
%PACKAGER%
Foobar McFooface <foobar@mcfooface.org>
%SIZE%
123
%VALIDATION%
pgp
"#;
let file = tempfile::NamedTempFile::new()?;
let mut output = File::create(&file)?;
write!(output, "{}", desc_data)?;
(file, desc_data)
};
let db_desc = DbDescFile::from_file_with_schema(
file.path(),
Some(DbDescSchema::V1(SchemaVersion::new(Version::new(1, 0, 0)))),
)?;
assert_eq!(db_desc.to_string(), desc_data);§Errors
Returns an error if:
- the file cannot be opened for reading,
- the contents cannot be parsed into any known
DbDescFilevariant, - or the provided
DbDescSchemadoes not match the contents of the file.
Source§fn from_reader_with_schema(
reader: impl Read,
schema: Option<DbDescSchema>,
) -> Result<Self, Error>
fn from_reader_with_schema( reader: impl Read, schema: Option<DbDescSchema>, ) -> Result<Self, Error>
Creates a DbDescFile from any readable stream, optionally validated using a
DbDescSchema.
Reads the reader to a string buffer and defers to DbDescFile::from_str_with_schema.
§Examples
use std::{fs::File, io::Write};
use alpm_common::MetadataFile;
use alpm_db::desc::{DbDescFile, DbDescSchema};
use alpm_types::{SchemaVersion, semver_version::Version};
// Prepare a reader with DB desc data (v2)
let (reader, desc_data) = {
let desc_data = r#"%NAME%
foo
%VERSION%
1.0.0-1
%BASE%
foo
%DESC%
An example package
%URL%
https://example.org/
%ARCH%
x86_64
%BUILDDATE%
1733737242
%INSTALLDATE%
1733737243
%PACKAGER%
Foobar McFooface <foobar@mcfooface.org>
%SIZE%
123
%VALIDATION%
pgp
%XDATA%
pkgtype=pkg
"#;
let file = tempfile::NamedTempFile::new()?;
let mut output = File::create(&file)?;
write!(output, "{}", desc_data)?;
(File::open(&file.path())?, desc_data)
};
let db_desc = DbDescFile::from_reader_with_schema(
reader,
Some(DbDescSchema::V2(SchemaVersion::new(Version::new(2, 0, 0)))),
)?;
assert_eq!(db_desc.to_string(), desc_data);§Errors
Returns an error if:
- the
readercannot be read to string, - the data cannot be parsed into a known
DbDescFilevariant, - or the provided
DbDescSchemadoes not match the parsed content.
Source§fn from_str_with_schema(
s: &str,
schema: Option<DbDescSchema>,
) -> Result<Self, Error>
fn from_str_with_schema( s: &str, schema: Option<DbDescSchema>, ) -> Result<Self, Error>
Creates a DbDescFile from a string slice, optionally validated using a DbDescSchema.
If schema is None, automatically infers the schema version by inspecting the input
(v1 = no %XDATA% section, v2 = has %XDATA%).
§Examples
use alpm_common::MetadataFile;
use alpm_db::desc::{DbDescFile, DbDescSchema};
use alpm_types::{SchemaVersion, semver_version::Version};
let v1_data = r#"%NAME%
foo
%VERSION%
1.0.0-1
%BASE%
foo
%DESC%
An example package
%URL%
https://example.org/
%ARCH%
x86_64
%BUILDDATE%
1733737242
%INSTALLDATE%
1733737243
%PACKAGER%
Foobar McFooface <foobar@mcfooface.org>
%SIZE%
123
%VALIDATION%
pgp
"#;
let dbdesc_v1 = DbDescFile::from_str_with_schema(
v1_data,
Some(DbDescSchema::V1(SchemaVersion::new(Version::new(1, 0, 0)))),
)?;
assert_eq!(dbdesc_v1.to_string(), v1_data);
let v2_data = r#"%NAME%
foo
%VERSION%
1.0.0-1
%BASE%
foo
%DESC%
An example package
%URL%
https://example.org/
%ARCH%
x86_64
%BUILDDATE%
1733737242
%INSTALLDATE%
1733737243
%PACKAGER%
Foobar McFooface <foobar@mcfooface.org>
%SIZE%
123
%VALIDATION%
pgp
%XDATA%
pkgtype=pkg
"#;
let dbdesc_v2 = DbDescFile::from_str_with_schema(
v2_data,
Some(DbDescSchema::V2(SchemaVersion::new(Version::new(2, 0, 0)))),
)?;
assert_eq!(dbdesc_v2.to_string(), v2_data);§Errors
Returns an error if:
- the input cannot be parsed into a valid
DbDescFile, - or the derived or provided schema does not match the detected format.
Source§impl PartialEq for DbDescSchema
impl PartialEq for DbDescSchema
impl StructuralPartialEq for DbDescSchema
Source§impl TryFrom<SchemaVersion> for DbDescSchema
impl TryFrom<SchemaVersion> for DbDescSchema
Source§fn try_from(value: SchemaVersion) -> Result<Self, Self::Error>
fn try_from(value: SchemaVersion) -> Result<Self, Self::Error>
Converts a SchemaVersion into a corresponding DbDescSchema.
§Errors
Returns an error if the major version of SchemaVersion does not
correspond to a known DbDescSchema variant.