Improved the way devices are instantiated from their respective configs
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2023-08-16 02:17:21 +02:00
parent ab5e47d1ff
commit b1506f8e63
15 changed files with 530 additions and 364 deletions

View File

@@ -73,7 +73,7 @@ pub fn device(attr: TokenStream, item: TokenStream) -> TokenStream {
let prefix = quote! {
pub trait #name<T: ?Sized + 'static> {
fn consume(self: Box<Self>) -> Option<Box<T>>;
fn is(&self) -> bool;
fn cast(&self) -> Option<&T>;
fn cast_mut(&mut self) -> Option<&mut T>;
}
@@ -95,8 +95,8 @@ pub fn device(attr: TokenStream, item: TokenStream) -> TokenStream {
where
T: #interface_ident + 'static,
{
default fn consume(self: Box<Self>) -> Option<Box<dyn #device_trait>> {
None
default fn is(&self) -> bool {
false
}
default fn cast(&self) -> Option<&(dyn #device_trait + 'static)> {
@@ -114,8 +114,8 @@ pub fn device(attr: TokenStream, item: TokenStream) -> TokenStream {
where
T: #interface_ident + #device_trait + 'static,
{
fn consume(self: Box<Self>) -> Option<Box<dyn #device_trait>> {
Some(self)
fn is(&self) -> bool {
true
}
fn cast(&self) -> Option<&(dyn #device_trait + 'static)> {