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§
Trait Implementations§
Source§impl FromStr for Mtree
impl FromStr for Mtree
Source§impl MetadataFile<MtreeSchema> for Mtree
impl MetadataFile<MtreeSchema> for Mtree
Source§fn from_file_with_schema(
file: impl AsRef<Path>,
schema: Option<MtreeSchema>,
) -> Result<Self, Error>
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 offile
, - or
schema
isSome
and theMtreeSchema
does not match the contents offile
.
Source§fn from_reader_with_schema(
reader: impl Read,
schema: Option<MtreeSchema>,
) -> Result<Self, Error>
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 decompresses potentially gzip compressed data on-the-fly).
Then 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 thereader
, - or
schema
isSome
and theMtreeSchema
does not match the contents of thereader
.
Source§fn from_str_with_schema(
s: &str,
schema: Option<MtreeSchema>,
) -> Result<Self, Error>
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
isSome
and the specified variant ofMtree
cannot be constructed froms
,schema
isNone
and- a
MtreeSchema
cannot be derived froms
, - or the detected variant of
Mtree
cannot be constructed froms
.
- a
impl StructuralPartialEq for Mtree
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more