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

1
impl_cast/.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
/target

16
impl_cast/Cargo.lock generated Normal file
View File

@@ -0,0 +1,16 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "impl_cast"
version = "0.1.0"
dependencies = [
"paste",
]
[[package]]
name = "paste"
version = "1.0.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cf1c2c742266c2f1041c914ba65355a83ae8747b05f208319784083583494b4b"

9
impl_cast/Cargo.toml Normal file
View File

@@ -0,0 +1,9 @@
[package]
name = "impl_cast"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
paste = "1.0.10"

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)
}
}
}
};
}