Attribute Macro ambassador::delegate_remote
source · #[delegate_remote]
Expand description
Make an existing type that lives outside you crate delegate traits to it’s members
This can be done by copy-pasting it’s definition into your code under this attribute.
If the type is a struct, not all the fields have to be public, only the ones being delegated to.
use ambassador::{delegate_remote, delegatable_trait};
#[delegatable_trait]
pub trait Shout {
fn shout(&self, input: &str) -> String;
}
pub struct Cat;
impl Shout for Cat {
fn shout(&self, input: &str) -> String {
format!("{} - meow!", input)
}
}
mod wrapped {
pub struct WrappedAnimals<A, B> {
pub foo: A,
pub bar: B,
baz: u32, // private field
}
}
use wrapped::*;
#[delegate_remote]
#[delegate(Shout, target = "bar")]
struct WrappedAnimals<A, B> {
foo: A,
bar: B,
// We don't even have to include baz since we don't delegate to it
}