add derive Register macro

This commit is contained in:
timeshifter
2023-01-12 23:07:27 +01:00
parent 73df8e8f42
commit 1b5302e459
9 changed files with 189 additions and 47 deletions
-31
View File
@@ -41,34 +41,3 @@ macro_rules! impl_backend_constants {
}
};
}
#[macro_export]
macro_rules! register_backends {
($first:ident, $($name:ident),*) => {
#[derive(Debug)]
pub(crate) enum Backends {
$first,
$(
$name,
)*
}
impl Backends {
pub fn iter() -> BackendIter {
BackendIter {
next: Some(Backends::$first),
}
}
fn get_backend(&self) -> Box<dyn Backend> {
match self {
Self::$first => Box::new($first::new()),
$(
Self::$name => Box::new($name::new()),
)*
}
}
}
}
}
+5 -15
View File
@@ -9,28 +9,18 @@ use std::process::Command;
use anyhow::{Context, Result};
use crate::register_backends;
use crate::{Group, Package};
use pacdef_macro::Register;
pub(crate) use todo_per_backend::ToDoPerBackend;
pub(in crate::backend) type Switches = &'static [&'static str];
pub(in crate::backend) type Text = &'static str;
register_backends!(Pacman, Rust);
// TODO find a way to include this in the `register_backends!` macro
pub(crate) use pacman::Pacman;
pub(crate) use rust::Rust;
// TODO find a way to include this in the `register_backends!` macro
impl Backends {
fn next(&self) -> Option<Self> {
match self {
Self::Pacman => Some(Self::Rust),
Self::Rust => None,
}
}
#[derive(Debug, Register)]
pub(crate) enum Backends {
Pacman,
Rust,
}
#[derive(Debug)]
+2
View File
@@ -12,3 +12,5 @@ mod ui;
pub use crate::core::Pacdef;
pub use crate::grouping::Group;
pub(crate) use crate::grouping::Package;
extern crate pacdef_macro;