3 releases (breaking)

0.3.0 Oct 20, 2023
0.2.0 Sep 14, 2023
0.1.0 May 31, 2023

#1675 in Procedural macros

Download history 14/week @ 2024-01-08 8/week @ 2024-01-15 6/week @ 2024-01-22 9/week @ 2024-01-29 10/week @ 2024-02-05 26/week @ 2024-02-12 31/week @ 2024-02-19 50/week @ 2024-02-26 33/week @ 2024-03-04 42/week @ 2024-03-11 89/week @ 2024-03-18 54/week @ 2024-03-25 73/week @ 2024-04-01 28/week @ 2024-04-08 28/week @ 2024-04-15

228 downloads per month
Used in 11 crates (via sov-modules-api)

MIT/Apache

115KB
2.5K SLoC

sov-modules-macros

This crate provides Rust macros specifically designed to be used with the Module System. When developing a module, the developer's primary focus should be on implementing the business logic, without having to worry about low-level details such as message serialization/deserialization or how messages are dispatched to the appropriate module.

To alleviate the burden of writing repetitive and mechanical code, this crate offers a collection of macros that generate the necessary boilerplate code.

The following derive macros are supported:

  1. The ModuleInfo: Derives the sov-modules-api::ModuleInfo implementation for the underlying type.
  2. The Genesis: Derives the sov-modules-api::Genesis implementation for the underlying type.
  3. The DispatchCall: Derives the sov-modules-api::DispatchCall implementation for the underlying type.
  4. The MessageCodec: Adds message serialization/deserialization functionality to the underlying type.

The definitions of the traits mentioned above can be found in the sov-modules-api crate.

Example usage:


/// Runtime is a collection of sov modules defined in the rollup.
#[derive(Genesis, DispatchCall, MessageCodec)]
pub struct Runtime<C: Context> {
    accounts: accounts::Accounts<C>,
    bank: sov_bank::Bank<C>,
    sequencer: sequencer::Sequencer<C>,
    ...
    some other modules
}

/// `Genesis` allow initialization of the rollup in following way:
runtime.genesis(&configuration, working_set)

/// `DispatchCall & MessageCodec` allows dispatching serialized messages to the appropriate module.
let call_result = RT::decode_call(message_data)

Dependencies

~4–14MB
~170K SLoC