#[derive(Publisher)]
{
// Attributes available to this derive:
#[subscribe]
}
Expand description
Derives the Publisher-trait for a structure.
The macro allows the attributes of a structure to be annotated with
#[subscribe] and generates an implementation of Publisher that will
subscribe and unsubscribe to all the annotated attributes. This allows
the structure to be used inside the until!-macro.
ยงExamples
Simple Publisher:
#[derive(Publisher)]
struct Foo(#[subscribe] Control<bool>);
impl Foo {
fn is_false(&self) -> bool {
!self.0.get()
}
}
let foo = Foo(Control::new(true));
// will wake up, once another part of the simulation sets
// the inner `Control` to `true`
until!(foo.is_false()).await;Multiple fields:
#[derive(Publisher)]
struct Foo {
field1: i32,
#[subscribe]
field2: Control<i32>,
#[subscribe]
field3: Control<bool>,
}Nesting of Publisher is possible, and generics are permitted:
#[derive(Publisher)]
struct Bar<T: ?Sized> {
#[subscribe]
foo: Foo,
data: T,
}Generic Publisher are also supported and qualify their implementation
using an extended where-bound for the individual subscriber fields.
#[derive(Publisher)]
struct Bar<T> {
#[subscribe]
maybe_publisher: T
}