add backend macro (WIP)

This commit is contained in:
steven-omaha
2023-01-12 13:49:42 +01:00
parent 17ee55da30
commit 49aa2b67e2
2 changed files with 91 additions and 25 deletions
+72
View File
@@ -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()),
)*
}
}
}
}
}