Finished basic google home implementation with some slight refactors along the way

This commit is contained in:
2022-12-16 06:54:31 +01:00
parent 995ff08784
commit e88e2fe48b
23 changed files with 551 additions and 208 deletions

31
impl_cast/src/lib.rs Normal file
View 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)
}
}
}
};
}