You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Yes it is possible by using delegate_to_remote_methods which allows foreign types to delegate to arbitrary methods. For example, in your case you could use:
If your trait includes methods with owned self or mutable reference &mut self receivers you would also need to specify target_mut and target_owned. For example:
use ambassador::{delegatable_trait, delegate_to_remote_methods};use std::ops::{Deref,DerefMut};#[delegatable_trait]traitFoo{fnhello(&self) -> String;fnconsume(self);fnmutate(&mutself);}traitIntoInner:Deref{fninto_inner(self) -> Self::Target;}// Unfortunately Box doesn't already have a method for this so we need to add oneimpl<T>IntoInnerforBox<T>{fninto_inner(self) -> Self::Target{*self}}#[delegate_to_remote_methods]#[delegate(Foo, target_ref = "deref", target_mut = "deref_mut", target_owned = "into_inner")]impl<T>Box<T>{fnderef(&self) -> &T;fnderef_mut(&mutself) -> &mutT;fninto_inner(self) -> T;}
If you have multiple traits you want to delegate, you can use the delegate attribute multiple times under the same delegate_to_remote_methods to reuse the impl block.
Is there a way to delegate traits directly from
Box<T>
,Arc<T>
, etc. without a wrapper? For example, something like the following:Will generate something like this:
The text was updated successfully, but these errors were encountered: