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

Download history 104/week @ 2025-01-31 51/week @ 2025-02-07 44/week @ 2025-02-14 7/week @ 2025-02-21 3/week @ 2025-02-28 3/week @ 2025-03-28 79/week @ 2025-04-04 30/week @ 2025-04-11

112 downloads per month
Used in rtactor

MIT license

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