RepoDescSchema

Enum RepoDescSchema 

Source
pub enum RepoDescSchema {
    V1(SchemaVersion),
    V2(SchemaVersion),
}
Expand description

An enum describing all valid alpm-repo-desc schemas.

Each variant corresponds to a specific revision of the specification.

Variants§

§

V1(SchemaVersion)

Schema for the alpm-repo-descv1 file format.

§

V2(SchemaVersion)

Schema for the alpm-repo-descv2 file format.

Trait Implementations§

Source§

impl Clone for RepoDescSchema

Source§

fn clone(&self) -> RepoDescSchema

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for RepoDescSchema

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for RepoDescSchema

Source§

fn default() -> Self

Returns the default schema variant (RepoDescSchema::V2).

Source§

impl Display for RepoDescSchema

Source§

fn fmt(&self, fmt: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl FileFormatSchema for RepoDescSchema

Source§

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,

Derives a RepoDescSchema from an alpm-repo-desc file on disk.

Opens the file and defers to RepoDescSchema::derive_from_reader.

§Errors

Returns an error if:

  • the file cannot be opened for reading,
  • or deriving a RepoDescSchema from its contents fails.
Source§

fn derive_from_reader(reader: impl Read) -> Result<Self, Error>
where Self: Sized,

Derives a RepoDescSchema from alpm-repo-desc data in a reader.

Reads the reader to a string and defers to RepoDescSchema::derive_from_str.

§Errors

Returns an error if:

  • reading from reader fails,
  • or deriving a RepoDescSchema from its contents fails.
Source§

fn derive_from_str(s: &str) -> Result<RepoDescSchema, Error>

Derives a RepoDescSchema from a string slice containing alpm-repo-desc data.

The parser uses a simple heuristic:

  • v1 → %MD5SUM% section present
  • v2 → no %MD5SUM% section present

This approach avoids relying on explicit version metadata, as the package repository desc format itself is not self-describing.

§Examples
use alpm_common::FileFormatSchema;
use alpm_repo_db::desc::RepoDescSchema;
use alpm_types::{SchemaVersion, semver_version::Version};

let v1_data = r#"%FILENAME%
example-meta-1.0.0-1-any.pkg.tar.zst

%NAME%
example-meta

%BASE%
example-meta

%VERSION%
1.0.0-1

%DESC%
An example meta package

%CSIZE%
4634

%ISIZE%
0

%MD5SUM%
d3b07384d113edec49eaa6238ad5ff00

%SHA256SUM%
b5bb9d8014a0f9b1d61e21e796d78dccdf1352f23cd32812f4850b878ae4944c

%PGPSIG%
iHUEABYKAB0WIQRizHP4hOUpV7L92IObeih9mi7GCAUCaBZuVAAKCRCbeih9mi7GCIlMAP9ws/jU4f580ZRQlTQKvUiLbAZOdcB7mQQj83hD1Nc/GwD/WIHhO1/OQkpMERejUrLo3AgVmY3b4/uGhx9XufWEbgE=

%URL%
https://example.org/

%LICENSE%
GPL-3.0-or-later

%ARCH%
any

%BUILDDATE%
1729181726

%PACKAGER%
Foobar McFooface <foobar@mcfooface.org>

"#;

assert_eq!(
    RepoDescSchema::V1(SchemaVersion::new(Version::new(1, 0, 0))),
    RepoDescSchema::derive_from_str(v1_data)?
);

let v2_data = r#"%FILENAME%
example-meta-1.0.0-1-any.pkg.tar.zst

%NAME%
example-meta

%BASE%
example-meta

%VERSION%
1.0.0-1

%DESC%
An example meta package

%CSIZE%
4634

%ISIZE%
0

%SHA256SUM%
b5bb9d8014a0f9b1d61e21e796d78dccdf1352f23cd32812f4850b878ae4944c

%URL%
https://example.org/

%LICENSE%
GPL-3.0-or-later

%ARCH%
any

%BUILDDATE%
1729181726

%PACKAGER%
Foobar McFooface <foobar@mcfooface.org>

"#;

assert_eq!(
    RepoDescSchema::V2(SchemaVersion::new(Version::new(2, 0, 0))),
    RepoDescSchema::derive_from_str(v2_data)?
);
§Errors

Returns an error only if internal conversion or string handling fails.

Source§

type Err = Error

The Error type to use.
Source§

impl FromStr for RepoDescSchema

Source§

fn from_str(s: &str) -> Result<RepoDescSchema, Self::Err>

Parses a RepoDescSchema 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§

type Err = Error

The associated error which can be returned from parsing.
Source§

impl MetadataFile<RepoDescSchema> for RepoDescFile

Source§

fn from_file_with_schema( file: impl AsRef<Path>, schema: Option<RepoDescSchema>, ) -> Result<Self, Error>

Creates a RepoDescFile from a file on disk, optionally validated using a RepoDescSchema.

Opens the file and defers to RepoDescFile::from_reader_with_schema.

§Examples
use std::{fs::File, io::Write};

use alpm_common::{FileFormatSchema, MetadataFile};
use alpm_repo_db::desc::{RepoDescFile, RepoDescSchema};
use alpm_types::{SchemaVersion, semver_version::Version};

// Prepare a file with package repository desc data (v1)
let (file, desc_data) = {
    let desc_data = r#"%FILENAME%
example-meta-1.0.0-1-any.pkg.tar.zst

%NAME%
example-meta

%BASE%
example-meta

%VERSION%
1.0.0-1

%DESC%
An example meta package

%CSIZE%
4634

%ISIZE%
0

%MD5SUM%
d3b07384d113edec49eaa6238ad5ff00

%SHA256SUM%
b5bb9d8014a0f9b1d61e21e796d78dccdf1352f23cd32812f4850b878ae4944c

%PGPSIG%
iHUEABYKAB0WIQRizHP4hOUpV7L92IObeih9mi7GCAUCaBZuVAAKCRCbeih9mi7GCIlMAP9ws/jU4f580ZRQlTQKvUiLbAZOdcB7mQQj83hD1Nc/GwD/WIHhO1/OQkpMERejUrLo3AgVmY3b4/uGhx9XufWEbgE=

%URL%
https://example.org/

%LICENSE%
GPL-3.0-or-later

%ARCH%
any

%BUILDDATE%
1729181726

%PACKAGER%
Foobar McFooface <foobar@mcfooface.org>

"#;
    let file = tempfile::NamedTempFile::new()?;
    let mut output = File::create(&file)?;
    write!(output, "{}", desc_data)?;
    (file, desc_data)
};

let repo_desc = RepoDescFile::from_file_with_schema(
    file.path(),
    Some(RepoDescSchema::V1(SchemaVersion::new(Version::new(
        1, 0, 0,
    )))),
)?;
assert_eq!(repo_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 RepoDescFile variant,
  • or the provided RepoDescSchema does not match the contents of the file.
Source§

fn from_reader_with_schema( reader: impl Read, schema: Option<RepoDescSchema>, ) -> Result<Self, Error>

Creates a RepoDescFile from any readable stream, optionally validated using a RepoDescSchema.

Reads the reader to a string buffer and defers to RepoDescFile::from_str_with_schema.

§Examples
use std::{fs::File, io::Write};

use alpm_common::MetadataFile;
use alpm_repo_db::desc::{RepoDescFile, RepoDescSchema};
use alpm_types::{SchemaVersion, semver_version::Version};

// Prepare a reader with package repository desc data (v2)
let (reader, desc_data) = {
    let desc_data = r#"%FILENAME%
example-meta-1.0.0-1-any.pkg.tar.zst

%NAME%
example-meta

%BASE%
example-meta

%VERSION%
1.0.0-1

%DESC%
An example meta package

%CSIZE%
4634

%ISIZE%
0

%SHA256SUM%
b5bb9d8014a0f9b1d61e21e796d78dccdf1352f23cd32812f4850b878ae4944c

%URL%
https://example.org/

%LICENSE%
GPL-3.0-or-later

%ARCH%
any

%BUILDDATE%
1729181726

%PACKAGER%
Foobar McFooface <foobar@mcfooface.org>

"#;
    let file = tempfile::NamedTempFile::new()?;
    let mut output = File::create(&file)?;
    write!(output, "{}", desc_data)?;
    (File::open(&file.path())?, desc_data)
};

let repo_desc = RepoDescFile::from_reader_with_schema(
    reader,
    Some(RepoDescSchema::V2(SchemaVersion::new(Version::new(
        2, 0, 0,
    )))),
)?;
assert_eq!(repo_desc.to_string(), desc_data);
§Errors

Returns an error if:

  • the reader cannot be read to string,
  • the data cannot be parsed into a known RepoDescFile variant,
  • or the provided RepoDescSchema does not match the parsed content.
Source§

fn from_str_with_schema( s: &str, schema: Option<RepoDescSchema>, ) -> Result<Self, Error>

Creates a RepoDescFile from a string slice, optionally validated using a RepoDescSchema.

If schema is None, automatically infers the schema version by inspecting the input (v1 if %MD5SUM% is present, v2 otherwise).

§Examples
use alpm_common::MetadataFile;
use alpm_repo_db::desc::{RepoDescFile, RepoDescSchema};
use alpm_types::{SchemaVersion, semver_version::Version};

let v1_data = r#"%FILENAME%
example-meta-1.0.0-1-any.pkg.tar.zst

%NAME%
example-meta

%BASE%
example-meta

%VERSION%
1.0.0-1

%DESC%
An example meta package

%CSIZE%
4634

%ISIZE%
0

%MD5SUM%
d3b07384d113edec49eaa6238ad5ff00

%SHA256SUM%
b5bb9d8014a0f9b1d61e21e796d78dccdf1352f23cd32812f4850b878ae4944c

%PGPSIG%
iHUEABYKAB0WIQRizHP4hOUpV7L92IObeih9mi7GCAUCaBZuVAAKCRCbeih9mi7GCIlMAP9ws/jU4f580ZRQlTQKvUiLbAZOdcB7mQQj83hD1Nc/GwD/WIHhO1/OQkpMERejUrLo3AgVmY3b4/uGhx9XufWEbgE=

%URL%
https://example.org/

%LICENSE%
GPL-3.0-or-later

%ARCH%
any

%BUILDDATE%
1729181726

%PACKAGER%
Foobar McFooface <foobar@mcfooface.org>

"#;

let repo_desc_v1 = RepoDescFile::from_str_with_schema(
    v1_data,
    Some(RepoDescSchema::V1(SchemaVersion::new(Version::new(
        1, 0, 0,
    )))),
)?;
assert_eq!(repo_desc_v1.to_string(), v1_data);

let v2_data = r#"%FILENAME%
example-meta-1.0.0-1-any.pkg.tar.zst

%NAME%
example-meta

%BASE%
example-meta

%VERSION%
1.0.0-1

%DESC%
An example meta package

%CSIZE%
4634

%ISIZE%
0

%SHA256SUM%
b5bb9d8014a0f9b1d61e21e796d78dccdf1352f23cd32812f4850b878ae4944c

%URL%
https://example.org/

%LICENSE%
GPL-3.0-or-later

%ARCH%
any

%BUILDDATE%
1729181726

%PACKAGER%
Foobar McFooface <foobar@mcfooface.org>

"#;

let repo_desc_v2 = RepoDescFile::from_str_with_schema(
    v2_data,
    Some(RepoDescSchema::V2(SchemaVersion::new(Version::new(
        2, 0, 0,
    )))),
)?;
assert_eq!(repo_desc_v2.to_string(), v2_data);
§Errors

Returns an error if:

  • the input cannot be parsed into a valid RepoDescFile,
  • or the derived or provided schema does not match the detected format.
Source§

type Err = Error

The Error type to use.
Source§

fn from_file(file: impl AsRef<Path>) -> Result<Self, Self::Err>
where Self: Sized,

Creates Self from file. Read more
Source§

fn from_stdin() -> Result<Self, Self::Err>
where Self: Sized,

Creates Self from stdin. Read more
Source§

fn from_stdin_with_schema(schema: Option<T>) -> Result<Self, Self::Err>
where Self: Sized,

Creates Self from stdin, optionally validated by a schema. Read more
Source§

fn from_reader(reader: impl Read) -> Result<Self, Self::Err>
where Self: Sized,

Creates Self from a Read implementer. Read more
Source§

impl PartialEq for RepoDescSchema

Source§

fn eq(&self, other: &RepoDescSchema) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl TryFrom<SchemaVersion> for RepoDescSchema

Source§

fn try_from(value: SchemaVersion) -> Result<Self, Self::Error>

Converts a SchemaVersion into a corresponding RepoDescSchema.

§Errors

Returns an error if the major version of SchemaVersion does not correspond to a known RepoDescSchema variant.

Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

impl Eq for RepoDescSchema

Source§

impl StructuralPartialEq for RepoDescSchema

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> AnyEq for T
where T: Any + PartialEq,

§

fn equals(&self, other: &(dyn Any + 'static)) -> bool

§

fn as_any(&self) -> &(dyn Any + 'static)

Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.