add backend macro (WIP)
This commit is contained in:
@@ -41,3 +41,75 @@ macro_rules! impl_backend_constants {
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
// #[macro_export]
|
||||
// macro_rules! register_backends {
|
||||
// ($first:ident, $($name:ident),*) => {
|
||||
// #[derive(Debug, Hash, PartialEq, Eq)]
|
||||
// pub(crate) enum Backends {
|
||||
// $first,
|
||||
// $(
|
||||
// $name,
|
||||
// )*
|
||||
// }
|
||||
//
|
||||
// impl Backends {
|
||||
// pub fn iter() -> BackendIter {
|
||||
// BackendIter {
|
||||
// next: Some(Backends::$first),
|
||||
// }
|
||||
// }
|
||||
// fn next(&self) -> Option<Self> {
|
||||
// match self {
|
||||
// $(
|
||||
// Self::$name => match $name {
|
||||
// $(
|
||||
// _ => Some(Self::$name),
|
||||
// )*
|
||||
// _ => None
|
||||
// },
|
||||
// )*
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! register_backends {
|
||||
($first:ident, $($name:ident),*) => {
|
||||
#[derive(Debug, Hash, PartialEq, Eq)]
|
||||
pub(crate) enum Backends {
|
||||
$first,
|
||||
$(
|
||||
$name,
|
||||
)*
|
||||
}
|
||||
|
||||
impl Backends {
|
||||
pub fn iter() -> BackendIter {
|
||||
BackendIter {
|
||||
next: Some(Backends::$first),
|
||||
}
|
||||
}
|
||||
|
||||
fn next(&self) -> Option<Self> {
|
||||
println!("Some({:?})", Self::$first);
|
||||
$(
|
||||
println!("{:?}", Self::$name);
|
||||
)*
|
||||
None
|
||||
}
|
||||
|
||||
fn get_backend(&self) -> Box<dyn Backend> {
|
||||
match self {
|
||||
Self::$first => Box::new($first::new()),
|
||||
$(
|
||||
Self::$name => Box::new($name::new()),
|
||||
)*
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+19
-25
@@ -9,41 +9,35 @@ use std::process::Command;
|
||||
|
||||
use anyhow::{Context, Result};
|
||||
|
||||
use crate::register_backends;
|
||||
use crate::{Group, Package};
|
||||
|
||||
pub(crate) use pacman::Pacman;
|
||||
pub(crate) use rust::Rust;
|
||||
pub(crate) use todo_per_backend::ToDoPerBackend;
|
||||
|
||||
pub(in crate::backend) type Switches = &'static [&'static str];
|
||||
pub(in crate::backend) type Text = &'static str;
|
||||
|
||||
#[derive(Debug, Hash, PartialEq, Eq)]
|
||||
pub(crate) enum Backends {
|
||||
Pacman,
|
||||
Rust,
|
||||
}
|
||||
pub(crate) use pacman::Pacman;
|
||||
pub(crate) use rust::Rust;
|
||||
|
||||
register_backends!(Pacman, Rust);
|
||||
|
||||
impl Backends {
|
||||
pub fn iter() -> BackendIter {
|
||||
BackendIter {
|
||||
next: Some(Backends::Pacman),
|
||||
}
|
||||
}
|
||||
// fn next(&self) -> Option<Self> {
|
||||
// match self {
|
||||
// Self::Pacman => Some(Self::Rust),
|
||||
// Self::Rust => Some(Self::Pip),
|
||||
// Self::Pip => None,
|
||||
// }
|
||||
// }
|
||||
|
||||
fn next(&self) -> Option<Self> {
|
||||
match self {
|
||||
Self::Pacman => Some(Self::Rust),
|
||||
Self::Rust => None,
|
||||
}
|
||||
}
|
||||
|
||||
fn get_backend(&self) -> Box<dyn Backend> {
|
||||
match self {
|
||||
Self::Pacman => Box::new(Pacman::new()),
|
||||
Self::Rust => Box::new(Rust::new()),
|
||||
}
|
||||
}
|
||||
// fn get_backend(&self) -> Box<dyn Backend> {
|
||||
// match self {
|
||||
// Self::Pacman => Box::new(Pacman::new()),
|
||||
// Self::Rust => Box::new(Rust::new()),
|
||||
// _ => todo!(),
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
|
||||
Reference in New Issue
Block a user