Print debug line with module arguments when run starts Make apt package manager non-interactive Move PackageList to dedicated module and make more impls utils::Cmd now can take environment variables
80 lines
1.9 KiB
Rust
80 lines
1.9 KiB
Rust
use serde::Serialize;
|
|
|
|
#[derive(Clone, Debug, Serialize)]
|
|
pub struct PackageList {
|
|
pub list: Vec<String>,
|
|
}
|
|
|
|
impl PackageList {
|
|
pub fn list(&self) -> & [ String ] {
|
|
&self.list
|
|
}
|
|
|
|
pub fn add<T: IntoPackageList>(self, add: T) -> PackageList {
|
|
let Self { mut list } = self;
|
|
|
|
let extend_with = add.into_package_list();
|
|
list.extend(extend_with.list);
|
|
|
|
PackageList {
|
|
list
|
|
}
|
|
}
|
|
}
|
|
|
|
/// Turn a stringy value or list of values into an actual package list.
|
|
/// Only implemented for &str and &str/String slices because apparently
|
|
/// there may be a future implementation that turns a slice of stringy values
|
|
/// into a stringy value, resulting in conflicting implementations.
|
|
/// https://stackoverflow.com/questions/63136970/how-do-i-work-around-the-upstream-crates-may-add-a-new-impl-of-trait-error
|
|
pub trait IntoPackageList {
|
|
fn into_package_list(self) -> PackageList;
|
|
}
|
|
|
|
impl IntoPackageList for &str {
|
|
fn into_package_list(self) -> PackageList {
|
|
PackageList {
|
|
list: vec!(self.to_string()),
|
|
}
|
|
}
|
|
}
|
|
|
|
impl IntoPackageList for String {
|
|
fn into_package_list(self) -> PackageList {
|
|
PackageList {
|
|
list: vec!(self),
|
|
}
|
|
}
|
|
}
|
|
|
|
impl<const C: usize> IntoPackageList for & [ &str; C ] {
|
|
fn into_package_list(self) -> PackageList {
|
|
PackageList {
|
|
list: self.iter().map(|x| x.to_string()).collect(),
|
|
}
|
|
}
|
|
}
|
|
|
|
impl<const C: usize> IntoPackageList for & [ String; C ] {
|
|
fn into_package_list(self) -> PackageList {
|
|
PackageList {
|
|
list: self.to_vec(),
|
|
}
|
|
}
|
|
}
|
|
|
|
impl IntoPackageList for Vec<&str> {
|
|
fn into_package_list(self) -> PackageList {
|
|
PackageList {
|
|
list: self.iter().map(|x| x.to_string()).collect(),
|
|
}
|
|
}
|
|
}
|
|
|
|
impl IntoPackageList for Vec<String> {
|
|
fn into_package_list(self) -> PackageList {
|
|
PackageList {
|
|
list: self,
|
|
}
|
|
}
|
|
}
|