Finished basic google home implementation with some slight refactors along the way
This commit is contained in:
31
impl_cast/src/lib.rs
Normal file
31
impl_cast/src/lib.rs
Normal file
@@ -0,0 +1,31 @@
|
||||
pub extern crate paste;
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! impl_cast {
|
||||
($base:ident, $trait:ident) => {
|
||||
$crate::paste::paste! {
|
||||
pub trait [< As $trait>] {
|
||||
fn cast(&self) -> Option<&dyn $trait>;
|
||||
fn cast_mut(&mut self) -> Option<&mut dyn $trait>;
|
||||
}
|
||||
|
||||
impl<T: $base> [< As $trait>] for T {
|
||||
default fn cast(&self) -> Option<&dyn $trait> {
|
||||
None
|
||||
}
|
||||
default fn cast_mut(&mut self) -> Option<&mut dyn $trait> {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: $base + $trait> [< As $trait>] for T {
|
||||
fn cast(&self) -> Option<&dyn $trait> {
|
||||
Some(self)
|
||||
}
|
||||
fn cast_mut(&mut self) -> Option<&mut dyn $trait> {
|
||||
Some(self)
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user