pub struct RepoFilesV1(Vec<PathBuf>);Expand description
The representation of alpm-repo-files data (version 1).
Tuple Fields§
§0: Vec<PathBuf>Trait Implementations§
Source§impl AsRef<[PathBuf]> for RepoFilesV1
impl AsRef<[PathBuf]> for RepoFilesV1
Source§impl Clone for RepoFilesV1
impl Clone for RepoFilesV1
Source§fn clone(&self) -> RepoFilesV1
fn clone(&self) -> RepoFilesV1
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for RepoFilesV1
impl Debug for RepoFilesV1
Source§impl Display for RepoFilesV1
impl Display for RepoFilesV1
Source§fn fmt(&self, f: &mut Formatter<'_>) -> Result
fn fmt(&self, f: &mut Formatter<'_>) -> Result
Returns the String representation of the RepoFilesV1.
§Examples
use std::path::PathBuf;
use alpm_repo_db::files::RepoFilesV1;
// An empty alpm-repo-files.
let expected = "%FILES%\n";
let files = RepoFilesV1::try_from(Vec::new())?;
assert_eq!(files.to_string(), expected);
// An alpm-repo-files with entries.
let expected = r#"%FILES%
usr/
usr/bin/
usr/bin/foo
"#;
let files = RepoFilesV1::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 RepoFilesV1
impl FromStr for RepoFilesV1
Source§fn from_str(s: &str) -> Result<Self, Self::Err>
fn from_str(s: &str) -> Result<Self, Self::Err>
Creates a new RepoFilesV1 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
- the first line does not contain the section header (“%FILES%”),
- there are lines following the section header, but they cannot be parsed as a
VecofPathBuf, - or
Self::try_fromVecofPathBuffails.
§Examples
use std::{path::PathBuf, str::FromStr};
use alpm_repo_db::files::RepoFilesV1;
// The section header is required; empty input is invalid.
let data = "";
assert!(RepoFilesV1::from_str(data).is_err());
// No files according to alpm-repo-files.
let data = "%FILES%";
let files = RepoFilesV1::from_str(data)?;
let data = "%FILES%\n";
let files = RepoFilesV1::from_str(data)?;
// Files according to alpm-repo-files.
let data = r#"%FILES%
usr/
usr/bin/
usr/bin/foo"#;
let files = RepoFilesV1::from_str(data)?;
// Files according to alpm-repo-files.
let data = r#"%FILES%
usr/
usr/bin/
usr/bin/foo
"#;
let files = RepoFilesV1::from_str(data)?;Source§impl Serialize for RepoFilesV1
impl Serialize for RepoFilesV1
Source§impl TryFrom<PathBuf> for RepoFilesV1
impl TryFrom<PathBuf> for RepoFilesV1
Source§fn try_from(value: PathBuf) -> Result<Self, Self::Error>
fn try_from(value: PathBuf) -> Result<Self, Self::Error>
Creates a new RepoFilesV1 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 RepoFilesV1 from this list.
§Errors
Returns an error if
alpm_common::relative_filesfails,- or
TryFromVecofPathBufforRepoFilesV1fails.
§Examples
use std::{
fs::{File, create_dir_all},
path::PathBuf,
};
use alpm_repo_db::files::RepoFilesV1;
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 = RepoFilesV1::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§impl TryFrom<Vec<PathBuf>> for RepoFilesV1
impl TryFrom<Vec<PathBuf>> for RepoFilesV1
Source§fn try_from(value: Vec<PathBuf>) -> Result<Self, Self::Error>
fn try_from(value: Vec<PathBuf>) -> Result<Self, Self::Error>
Creates a new RepoFilesV1 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
valuecontains absolute paths,valuecontains (non top-level) paths without a parent directory present invalue,- or
valuecontains duplicate paths.
§Examples
use std::path::PathBuf;
use alpm_repo_db::files::RepoFilesV1;
let paths: Vec<PathBuf> = vec![
PathBuf::from("usr/"),
PathBuf::from("usr/bin/"),
PathBuf::from("usr/bin/foo"),
];
let files = RepoFilesV1::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!(RepoFilesV1::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!(RepoFilesV1::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!(RepoFilesV1::try_from(paths).is_err());