Finished basic google home implementation with some slight refactors along the way
This commit is contained in:
1
impl_cast/.gitignore
vendored
Normal file
1
impl_cast/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
/target
|
||||
16
impl_cast/Cargo.lock
generated
Normal file
16
impl_cast/Cargo.lock
generated
Normal 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
9
impl_cast/Cargo.toml
Normal 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
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