pub trait SailsEvent: Encode {
// Required method
fn encoded_event_name(&self) -> &'static [u8] ⓘ;
// Provided method
fn skip_bytes() -> usize { ... }
}Expand description
Trait for encoding events that can be emitted by Sails programs.
This trait is used to define events that can be emitted by Sails programs, allowing them to be encoded into a byte slice.
The SailsEvent trait extends the Encode trait, which means that any type implementing SailsEvent
must also implement the Encode trait.
The skip_bytes method is used to determine how many bytes should be skipped when encoding the event,
which is particularly relevant for enum variants where the first byte is reserved for the index of the variant.
/// # Examples
Given an event definition:
#[sails_rs::event]
#[derive(sails_rs::Encode, sails_rs::TypeInfo)]
#[codec(crate = sails_rs::scale_codec)]
#[scale_info(crate = sails_rs::scale_info)]
pub enum Events {
MyEvent {
sender: uint128,
amount: uint128,
note: String,
},
}Required Methods§
Sourcefn encoded_event_name(&self) -> &'static [u8] ⓘ
fn encoded_event_name(&self) -> &'static [u8] ⓘ
Returns the encoded event name as a byte slice.
Provided Methods§
Sourcefn skip_bytes() -> usize
fn skip_bytes() -> usize
The number of bytes to skip when encoding the event.
For enums, this is always 1 byte, which is reserved for the index of the event enum variant.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.