3 unstable releases
new 0.5.1 | Apr 18, 2025 |
---|---|
0.5.0 | Feb 3, 2025 |
0.1.0 | Nov 17, 2024 |
#100 in #i32
112 downloads per month
Used in rtactor
18KB
220 lines
Proc macros for the rtactor library.
Generate a Response enum from a Request enum with derive(ResponseEnum)
#[derive(ResponseEnum)]
pub enum Request {
SetValue{val: i32},
#[response_val(i32)]
GetValue{},
}
Will generate:
pub enum Response
{
SetValue(),
GetValue(i32)
}
Generate a synchronous access trait from a Notification enum with SyncNotifier
#[derive(SyncNotifier)]
pub enum Notification {
TemperatureChanged{temp: float}
}
Will generate:
pub trait SyncNotifier : ::rtactor::SyncAccessData
{
temperature_changed(&mut self, temp: float) -> Result<(), ::rtactor::Error> {[...]}
}
A structure can add the generated methods by deriving SyncNotifier
and
implementing the methods of SyncAccessData
. The macro define_sync_accessor!()
found in create rtactor
can be used to generate a struct that
allows easy access with its internal ActiveActor:
define_sync_accessor!(MyNotifSyncAccessor, SyncNotifier)
fn test(addr: rtactor::Addr)
{
let accessor = MyNotifSyncAccessor::new(&addr);
accessor.temperature_changed(13.2f32).unwarp();
}
Generate a synchronous access trait from a Request enum with SyncRequester
#[derive(ResponseEnum, SyncRequester)]
pub enum Request {
SetValue{val: i32},
#[response_val(i32)]
GetValue{},
}
Will generate for the SyncRequester
part:
pub trait SyncRequester: ::rtactor::SyncAccessor
{
fn set_value(&mut self, val: i32) -> Result<(), ::rtactor::Error> {[...]}
fn get_value(&mut self) -> Result<i32, ::rtactor::Error> {[...]}
}
A structure can add the generated methods by deriving SyncRequester
and
implementing the methods of SyncAccessor
. The macro define_sync_notifier!()
found in create rtactor
can be used to generate a struct that
allows easy access with its internal ActiveActor:
define_sync_accessor!(MySyncAccessor, SyncNotifier, SyncRequester)
fn test(addr: rtactor::Addr)
{
let accessor = MyNotifSyncAccessor::new(&addr);
accessor.temperature_changed(13.2f32).unwarp();
accessor.set_value(72).unwrap();
assert!(accessor.get_value().unwrap() == 72);
}
RTactor framework macros
These are the macros that are used in the RTactor framework. Please see rtactor for details.
Dependencies
~1.5MB
~39K SLoC