combine impls of Backends

This commit is contained in:
timeshifter
2023-01-09 17:26:03 +01:00
parent 20a37c4d5f
commit 86674c3fa1
+13 -15
View File
@@ -10,8 +10,8 @@ use crate::Package;
pub use pacman::Pacman; pub use pacman::Pacman;
pub use rust::Rust; pub use rust::Rust;
pub type Switches = &'static [&'static str]; pub(in crate::backend) type Switches = &'static [&'static str];
pub type Text = &'static str; pub(in crate::backend) type Text = &'static str;
#[derive(Debug)] #[derive(Debug)]
pub enum Backends { pub enum Backends {
@@ -23,6 +23,17 @@ impl Backends {
pub fn iter() -> BackendIter { pub fn iter() -> BackendIter {
BackendIter(Some(Self::Pacman)) BackendIter(Some(Self::Pacman))
} }
pub fn get(&self) -> Box<dyn Backend> {
match self {
Self::Pacman => Box::new(Pacman {
packages: HashSet::new(),
}),
Self::Rust => Box::new(Rust {
packages: HashSet::new(),
}),
}
}
} }
pub struct BackendIter(Option<Backends>); pub struct BackendIter(Option<Backends>);
@@ -45,19 +56,6 @@ impl Iterator for BackendIter {
} }
} }
impl Backends {
pub fn get(&self) -> Box<dyn Backend> {
match self {
Self::Pacman => Box::new(Pacman {
packages: HashSet::new(),
}),
Self::Rust => Box::new(Rust {
packages: HashSet::new(),
}),
}
}
}
pub trait Backend { pub trait Backend {
fn get_binary(&self) -> Text; fn get_binary(&self) -> Text;
fn get_section(&self) -> Text; fn get_section(&self) -> Text;