use serde::Serialize; #[derive(Clone, Debug, Serialize)] pub struct PackageList { pub list: Vec, } impl PackageList { pub fn list(&self) -> & [ String ] { &self.list } pub fn add(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 IntoPackageList for & [ &str; C ] { fn into_package_list(self) -> PackageList { PackageList { list: self.iter().map(|x| x.to_string()).collect(), } } } impl 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 { fn into_package_list(self) -> PackageList { PackageList { list: self, } } }