add infallible From<String> for Package
This commit is contained in:
@@ -47,7 +47,7 @@ fn get_explicitly_installed_packages_from_alpm() -> HashSet<String> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn convert_to_pacdef_packages(packages: HashSet<String>) -> HashSet<Package> {
|
fn convert_to_pacdef_packages(packages: HashSet<String>) -> HashSet<Package> {
|
||||||
packages.into_iter().filter_map(Package::try_from).collect()
|
packages.into_iter().map(Package::from).collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Pacman {
|
impl Pacman {
|
||||||
|
|||||||
@@ -14,6 +14,16 @@ fn remove_all_but_package_name(s: &str) -> &str {
|
|||||||
.trim() // remove whitespace
|
.trim() // remove whitespace
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl From<String> for Package {
|
||||||
|
fn from(value: String) -> Self {
|
||||||
|
let trimmed = remove_all_but_package_name(&value);
|
||||||
|
debug_assert!(!trimmed.is_empty(), "empty package names are not allowed");
|
||||||
|
|
||||||
|
let (name, repo) = Self::split_into_name_and_repo(trimmed);
|
||||||
|
Self { name, repo }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Package {
|
impl Package {
|
||||||
fn split_into_name_and_repo(s: &str) -> (String, Option<String>) {
|
fn split_into_name_and_repo(s: &str) -> (String, Option<String>) {
|
||||||
let mut iter = s.split('/').rev();
|
let mut iter = s.split('/').rev();
|
||||||
|
|||||||
Reference in New Issue
Block a user