This commit is contained in:
parent
f8d1975f85
commit
33fcb95dfa
|
@ -90,39 +90,42 @@ pub fn device(attr: TokenStream, item: TokenStream) -> TokenStream {
|
|||
.iter()
|
||||
.map(|device_trait| {
|
||||
quote! {
|
||||
// Default impl
|
||||
impl<T> #name<dyn #device_trait> for T
|
||||
where
|
||||
T: #interface_ident + #device_trait + 'static,
|
||||
{
|
||||
fn consume(self: Box<Self>) -> Option<Box<dyn #device_trait>> {
|
||||
Some(self)
|
||||
}
|
||||
|
||||
fn cast(&self) -> Option<&(dyn #device_trait + 'static)> {
|
||||
Some(self)
|
||||
}
|
||||
|
||||
fn cast_mut(&mut self) -> Option<&mut (dyn #device_trait + 'static)> {
|
||||
Some(self)
|
||||
}
|
||||
where
|
||||
T: #interface_ident + 'static,
|
||||
{
|
||||
default fn consume(self: Box<Self>) -> Option<Box<dyn #device_trait>> {
|
||||
None
|
||||
}
|
||||
|
||||
impl<T> #name<dyn #device_trait> for T
|
||||
where
|
||||
T: #interface_ident + ?Sized,
|
||||
{
|
||||
default fn consume(self: Box<Self>) -> Option<Box<dyn #device_trait>> {
|
||||
None
|
||||
}
|
||||
|
||||
default fn cast(&self) -> Option<&(dyn #device_trait + 'static)> {
|
||||
None
|
||||
}
|
||||
|
||||
default fn cast_mut(&mut self) -> Option<&mut (dyn #device_trait + 'static)> {
|
||||
None
|
||||
}
|
||||
default fn cast(&self) -> Option<&(dyn #device_trait + 'static)> {
|
||||
None
|
||||
}
|
||||
|
||||
default fn cast_mut(&mut self) -> Option<&mut (dyn #device_trait + 'static)> {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
// Specialization, should not cause any unsoundness as we dispatch based on
|
||||
// #device_trait
|
||||
impl<T> #name<dyn #device_trait> for T
|
||||
where
|
||||
T: #interface_ident + #device_trait + 'static,
|
||||
{
|
||||
fn consume(self: Box<Self>) -> Option<Box<dyn #device_trait>> {
|
||||
Some(self)
|
||||
}
|
||||
|
||||
fn cast(&self) -> Option<&(dyn #device_trait + 'static)> {
|
||||
Some(self)
|
||||
}
|
||||
|
||||
fn cast_mut(&mut self) -> Option<&mut (dyn #device_trait + 'static)> {
|
||||
Some(self)
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
.fold(quote! {}, |acc, x| {
|
||||
|
@ -149,7 +152,7 @@ pub fn device_trait(_attr: TokenStream, item: TokenStream) -> TokenStream {
|
|||
let mut interface: ItemTrait = parse_macro_input!(item);
|
||||
|
||||
interface.supertraits.push(TypeParamBound::Verbatim(quote! {
|
||||
::core::marker::Sync + ::core::marker::Send + 'static
|
||||
::core::marker::Sync + ::core::marker::Send
|
||||
}));
|
||||
|
||||
#[cfg(feature = "debug")]
|
||||
|
|
Loading…
Reference in New Issue
Block a user