FilesV1

Struct FilesV1 

Source
pub struct FilesV1(Vec<PathBuf>);
Expand description

The representation of alpm-files data (version 1).

Tuple Fields§

§0: Vec<PathBuf>

Trait Implementations§

Source§

impl AsRef<[PathBuf]> for FilesV1

Source§

fn as_ref(&self) -> &[PathBuf]

Returns a reference to the inner Vec of PathBufs.

Source§

impl Clone for FilesV1

Source§

fn clone(&self) -> FilesV1

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 FilesV1

Source§

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

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

impl FilesStyleToString for FilesV1

Source§

fn to_string(&self, style: FilesStyle) -> String

Returns the String representation of the FilesV1.

The formatting of the returned string depends on the provided FilesStyle.

§Examples
use std::path::PathBuf;

use alpm_files::{FilesStyle, FilesStyleToString, FilesV1};

// An empty alpm-db-files.
let expected = "";
let files = FilesV1::try_from(Vec::new())?;
assert_eq!(files.to_string(FilesStyle::Db), expected);

// An alpm-db-files with entries.
let expected = r#"%FILES%
usr/
usr/bin/
usr/bin/foo

"#;
let files = FilesV1::try_from(vec![
    PathBuf::from("usr/"),
    PathBuf::from("usr/bin/"),
    PathBuf::from("usr/bin/foo"),
])?;
assert_eq!(files.to_string(FilesStyle::Db), expected);

// An empty alpm-repo-files.
let expected = "%FILES%\n";
let files = FilesV1::try_from(Vec::new())?;
assert_eq!(files.to_string(FilesStyle::Repo), expected);

// An alpm-repo-files with entries.
let expected = r#"%FILES%
usr/
usr/bin/
usr/bin/foo
"#;
let files = FilesV1::try_from(vec![
    PathBuf::from("usr/"),
    PathBuf::from("usr/bin/"),
    PathBuf::from("usr/bin/foo"),
])?;
assert_eq!(files.to_string(FilesStyle::Repo), expected);
Source§

impl FromStr for FilesV1

Source§

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

Creates a new FilesV1 from a string slice.

§Note

Delegates to the TryFrom Vec of PathBuf implementation, after the string slice has been parsed as a Vec of PathBuf.

§Errors

Returns an error, if

  • value is not empty and the first line does not contain the section header (“%FILES%”),
  • there are lines following the section header, but they cannot be parsed as a Vec of PathBuf,
  • or Self::try_from Vec of PathBuf fails.
§Examples
use std::{path::PathBuf, str::FromStr};

use alpm_files::FilesV1;
use winnow::Parser;

// No files according to alpm-db-files.
let data = "";
let files = FilesV1::from_str(data)?;

// No files according to alpm-repo-files.
let data = "%FILES%";
let files = FilesV1::from_str(data)?;
let data = "%FILES%\n";
let files = FilesV1::from_str(data)?;

// Files according to alpm-repo-files.
let data = r#"%FILES%
usr/
usr/bin/
usr/bin/foo"#;
let files = FilesV1::from_str(data)?;

// Files according to alpm-db-files.
let data = r#"%FILES%
usr/
usr/bin/
usr/bin/foo
"#;
let files = FilesV1::from_str(data)?;
Source§

type Err = Error

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

impl TryFrom<PathBuf> for FilesV1

Source§

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

Creates a new FilesV1 from all files and directories in a directory.

§Note

Delegates to alpm_common::relative_files to get a sorted list of all files and directories in the directory value (relative to value). Afterwards, tries to construct a FilesV1 from this list.

§Errors

Returns an error if

§Examples
use std::{
    fs::{File, create_dir_all},
    path::PathBuf,
};

use alpm_files::FilesV1;
use tempfile::tempdir;

let temp_dir = tempdir()?;
let path = temp_dir.path();
create_dir_all(path.join("usr/bin/"))?;
File::create(path.join("usr/bin/foo"))?;

let files = FilesV1::try_from(path.to_path_buf())?;
assert_eq!(
    files.as_ref(),
    vec![
        PathBuf::from("usr/"),
        PathBuf::from("usr/bin/"),
        PathBuf::from("usr/bin/foo")
    ]
);
Source§

type Error = Error

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

impl TryFrom<Vec<PathBuf>> for FilesV1

Source§

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

Creates a new FilesV1 from a Vec of PathBuf.

The provided value is sorted and checked for non top-level paths without a parent, as well as any duplicate paths.

§Errors

Returns an error if

  • value contains absolute paths,
  • value contains (non top-level) paths without a parent directory present in value,
  • or value contains duplicate paths.
§Examples
use std::path::PathBuf;

use alpm_files::FilesV1;

let paths: Vec<PathBuf> = vec![
    PathBuf::from("usr/"),
    PathBuf::from("usr/bin/"),
    PathBuf::from("usr/bin/foo"),
];
let files = FilesV1::try_from(paths)?;

// Absolute paths are not allowed.
let paths: Vec<PathBuf> = vec![
    PathBuf::from("/usr/"),
    PathBuf::from("/usr/bin/"),
    PathBuf::from("/usr/bin/foo"),
];
assert!(FilesV1::try_from(paths).is_err());

// Every path (excluding top-level paths) must have a parent.
let paths: Vec<PathBuf> = vec![PathBuf::from("usr/bin/"), PathBuf::from("usr/bin/foo")];
assert!(FilesV1::try_from(paths).is_err());

// Every path must be unique.
let paths: Vec<PathBuf> = vec![
    PathBuf::from("usr/"),
    PathBuf::from("usr/"),
    PathBuf::from("usr/bin/"),
    PathBuf::from("usr/bin/foo"),
];
assert!(FilesV1::try_from(paths).is_err());
Source§

type Error = Error

The type returned in the event of a conversion error.

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