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 anyhow::{Context, Result};
|
||||||
|
|
||||||
|
use crate::register_backends;
|
||||||
use crate::{Group, Package};
|
use crate::{Group, Package};
|
||||||
|
|
||||||
pub(crate) use pacman::Pacman;
|
|
||||||
pub(crate) use rust::Rust;
|
|
||||||
pub(crate) use todo_per_backend::ToDoPerBackend;
|
pub(crate) use todo_per_backend::ToDoPerBackend;
|
||||||
|
|
||||||
pub(in crate::backend) type Switches = &'static [&'static str];
|
pub(in crate::backend) type Switches = &'static [&'static str];
|
||||||
pub(in crate::backend) type Text = &'static str;
|
pub(in crate::backend) type Text = &'static str;
|
||||||
|
|
||||||
#[derive(Debug, Hash, PartialEq, Eq)]
|
pub(crate) use pacman::Pacman;
|
||||||
pub(crate) enum Backends {
|
pub(crate) use rust::Rust;
|
||||||
Pacman,
|
|
||||||
Rust,
|
register_backends!(Pacman, Rust);
|
||||||
}
|
|
||||||
|
|
||||||
impl Backends {
|
impl Backends {
|
||||||
pub fn iter() -> BackendIter {
|
// fn next(&self) -> Option<Self> {
|
||||||
BackendIter {
|
// match self {
|
||||||
next: Some(Backends::Pacman),
|
// Self::Pacman => Some(Self::Rust),
|
||||||
}
|
// Self::Rust => Some(Self::Pip),
|
||||||
}
|
// Self::Pip => None,
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
fn next(&self) -> Option<Self> {
|
// fn get_backend(&self) -> Box<dyn Backend> {
|
||||||
match self {
|
// match self {
|
||||||
Self::Pacman => Some(Self::Rust),
|
// Self::Pacman => Box::new(Pacman::new()),
|
||||||
Self::Rust => None,
|
// Self::Rust => Box::new(Rust::new()),
|
||||||
}
|
// _ => todo!(),
|
||||||
}
|
// }
|
||||||
|
// }
|
||||||
fn get_backend(&self) -> Box<dyn Backend> {
|
|
||||||
match self {
|
|
||||||
Self::Pacman => Box::new(Pacman::new()),
|
|
||||||
Self::Rust => Box::new(Rust::new()),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
|||||||
Reference in New Issue
Block a user