Skip to main content

arc_wrap

Attribute Macro arc_wrap 

Source
#[arc_wrap]
Expand description

Automatically wraps a struct with an Inner postfix in an Arc

This macro generates:

  1. A wrapper struct that contains Arc<OriginalStructInner>
  2. A Clone implementation for the wrapper
  3. A Deref implementation that derefs to the inner struct
  4. A new function that takes the inner struct and wraps it in Arc

§Example

use synapse_macros::arc_wrap;

#[arc_wrap]
pub struct MyService {
    pub data: String,
    pub count: u32,
}

// This generates:
// pub struct MyServiceInner { pub data: String, pub count: u32 }
// pub struct MyService(Arc<MyServiceInner>);
// impl Clone for MyService { ... }
// impl Deref for MyService { ... }
// impl MyService { pub fn new(inner: MyServiceInner) -> Self { ... } }