alpm_mtree::mtree

Enum Mtree

Source
pub enum Mtree {
    V1(Vec<Path>),
    V2(Vec<Path>),
}
Expand description

A representation of the ALPM-MTREE file format.

Tracks all available versions of the file format.

Variants§

§

V1(Vec<Path>)

§

V2(Vec<Path>)

Trait Implementations§

Source§

impl Clone for Mtree

Source§

fn clone(&self) -> Mtree

Returns a copy 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 Mtree

Source§

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

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

impl Display for Mtree

Source§

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

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

impl FromStr for Mtree

Source§

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

Creates a Mtree from string slice s.

Calls Mtree::from_str_with_schema with schema set to None.

§Errors

Returns an error if

  • a MtreeSchema cannot be derived from s,
  • or the detected variant of Mtree cannot be constructed from s.
Source§

type Err = Error

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

impl MetadataFile<MtreeSchema> for Mtree

Source§

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

Creates a Mtree from file, optionally validated using a MtreeSchema.

Opens the file and defers to Mtree::from_reader_with_schema.

§Note

To automatically derive the MtreeSchema, use Mtree::from_file.

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

use alpm_common::{FileFormatSchema, MetadataFile};
use alpm_mtree::{Mtree, MtreeSchema};
use alpm_types::{SchemaVersion, semver_version::Version};

// Prepare a file with ALPM-MTREE data
let file = {
    let mtree_data = r#"#mtree
/set mode=644 uid=0 gid=0 type=file
./some_file time=1700000000.0 size=1337 sha256digest=0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef
./some_link type=link link=some_file time=1700000000.0
./some_dir type=dir time=1700000000.0
"#;
    let mtree_file = tempfile::NamedTempFile::new()?;
    let mut output = File::create(&mtree_file)?;
    write!(output, "{}", mtree_data)?;
    mtree_file
};

let mtree = Mtree::from_file_with_schema(
    file.path().to_path_buf(),
    Some(MtreeSchema::V2(SchemaVersion::new(Version::new(2, 0, 0)))),
)?;
§Errors

Returns an error if

  • the file cannot be opened for reading,
  • no variant of Mtree can be constructed from the contents of file,
  • or schema is Some and the MtreeSchema does not match the contents of file.
Source§

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

Creates a Mtree from a reader, optionally validated using a MtreeSchema.

Reads the reader to string and defers to Mtree::from_str_with_schema.

§Note

To automatically derive the MtreeSchema, use Mtree::from_reader.

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

use alpm_common::MetadataFile;
use alpm_mtree::{Mtree, MtreeSchema};
use alpm_types::{SchemaVersion, semver_version::Version};

// Prepare a reader with ALPM-MTREE data
let reader = {
    let mtree_data = r#"#mtree
/set mode=644 uid=0 gid=0 type=file
./some_file time=1700000000.0 size=1337 sha256digest=0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef
./some_link type=link link=some_file time=1700000000.0
./some_dir type=dir time=1700000000.0
"#;
    let mtree_file = tempfile::NamedTempFile::new()?;
    let mut output = File::create(&mtree_file)?;
    write!(output, "{}", mtree_data)?;
    File::open(&mtree_file.path())?
};

let mtree = Mtree::from_reader_with_schema(
    reader,
    Some(MtreeSchema::V2(SchemaVersion::new(Version::new(2, 0, 0)))),
)?;
§Errors

Returns an error if

  • the reader cannot be read to string,
  • no variant of Mtree can be constructed from the contents of the reader,
  • or schema is Some and the MtreeSchema does not match the contents of the reader.
Source§

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

Creates a Mtree from string slice, optionally validated using a MtreeSchema.

If schema is None attempts to detect the MtreeSchema from s. Attempts to create a Mtree variant that corresponds to the MtreeSchema.

§Note

To automatically derive the MtreeSchema, use Mtree::from_str.

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

use alpm_common::MetadataFile;
use alpm_mtree::{Mtree, MtreeSchema};
use alpm_types::{SchemaVersion, semver_version::Version};

let mtree_v2 = r#"
#mtree
/set mode=644 uid=0 gid=0 type=file
./some_file time=1700000000.0 size=1337 sha256digest=0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef
./some_link type=link link=some_file time=1700000000.0
./some_dir type=dir time=1700000000.0
"#;
let mtree = Mtree::from_str_with_schema(
    mtree_v2,
    Some(MtreeSchema::V2(SchemaVersion::new(Version::new(2, 0, 0)))),
)?;

let mtree_v1 = r#"
#mtree
/set mode=644 uid=0 gid=0 type=file
./some_file time=1700000000.0 size=1337 sha256digest=0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef md5digest=d3b07384d113edec49eaa6238ad5ff00
./some_link type=link link=some_file time=1700000000.0
./some_dir type=dir time=1700000000.0
"#;
let mtree = Mtree::from_str_with_schema(
    mtree_v1,
    Some(MtreeSchema::V1(SchemaVersion::new(Version::new(1, 0, 0)))),
)?;
§Errors

Returns an error if

  • schema is Some and the specified variant of Mtree cannot be constructed from s,
  • schema is None and
    • a MtreeSchema cannot be derived from s,
    • or the detected variant of Mtree cannot be constructed from s.
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 Serialize for Mtree

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

§

impl Freeze for Mtree

§

impl RefUnwindSafe for Mtree

§

impl Send for Mtree

§

impl Sync for Mtree

§

impl Unpin for Mtree

§

impl UnwindSafe for Mtree

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
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, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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.

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.
§

impl<T> ErasedDestructor for T
where T: 'static,

§

impl<T> MaybeSendSync for T