DbFilesV1

Struct DbFilesV1 

Source
pub struct DbFilesV1 {
    files: Vec<PathBuf>,
    backup: Vec<BackupEntry>,
}
Expand description

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

Fields§

§files: Vec<PathBuf>§backup: Vec<BackupEntry>

Implementations§

Source§

impl DbFilesV1

Source

pub fn backups(&self) -> &[BackupEntry]

Returns the backup entries tracked for this file listing.

Source

fn try_from_parts( paths: Vec<PathBuf>, backup: Vec<BackupEntry>, ) -> Result<Self, Error>

Trait Implementations§

Source§

impl AsRef<[PathBuf]> for DbFilesV1

Source§

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

Returns a reference to the inner Vec of PathBufs.

Source§

impl Clone for DbFilesV1

Source§

fn clone(&self) -> DbFilesV1

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 DbFilesV1

Source§

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

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

impl Display for DbFilesV1

Source§

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

Returns the String representation of the DbFilesV1.

§Examples
use std::path::PathBuf;

use alpm_db::files::DbFilesV1;

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

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

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

impl FromStr for DbFilesV1

Source§

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

Creates a new DbFilesV1 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_db::files::DbFilesV1;
use winnow::Parser;

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

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

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

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

type Err = Error

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

impl Serialize for DbFilesV1

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

impl TryFrom<(Vec<PathBuf>, Vec<BackupEntry>)> for DbFilesV1

Source§

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

Creates a new DbFilesV1 from a Vec of PathBuf and backup entries.

Source§

type Error = Error

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

impl TryFrom<PathBuf> for DbFilesV1

Source§

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

Creates a new DbFilesV1 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 DbFilesV1 from this list.

§Errors

Returns an error if

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

use alpm_db::files::DbFilesV1;
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 = DbFilesV1::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 DbFilesV1

Source§

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

Creates a new DbFilesV1 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_db::files::DbFilesV1;

let paths: Vec<PathBuf> = vec![
    PathBuf::from("usr/"),
    PathBuf::from("usr/bin/"),
    PathBuf::from("usr/bin/foo"),
];
let files = DbFilesV1::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!(DbFilesV1::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!(DbFilesV1::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!(DbFilesV1::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> 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.