Skip to main content

EventRegistry

Struct EventRegistry 

Source
pub struct EventRegistry { /* private fields */ }
๐Ÿ‘ŽDeprecated since 0.1.0:

Use Bevy ECS events (scarab-client/src/events/bevy_events.rs) instead of Arc<Mutex<EventRegistry>>. See crates/scarab-plugin-api/src/events/registry.rs module docs for migration guide.

Expand description

Central registry for event handlers

DEPRECATED: Use Bevy ECS events instead. See module documentation for migration guide.

This registry uses Arc<Mutex<>> for thread synchronization, which is incompatible with Bevyโ€™s lock-free ECS architecture. The daemon still uses this for plugin-side event handling, but client-side code should use typed Bevy events.

ยงMigration Path

  • Daemon plugins: Continue using DaemonEventDispatcher which wraps this registry
  • Client code: Use typed events from scarab-client/src/events/bevy_events.rs
  • New code: Always prefer Bevy events over this registry

ยงThread Safety

The registry is NOT thread-safe by default. Wrap it in a Mutex or RwLock for concurrent access from multiple threads.

Implementationsยง

Sourceยง

impl EventRegistry

Source

pub fn new() -> Self

Create a new empty event registry

Source

pub fn register( &mut self, event_type: EventType, priority: i32, plugin_name: &str, handler: EventHandler, ) -> u64

Register a new event handler

ยงArguments
  • event_type - Type of event to listen for
  • priority - Handler priority (higher values = called first)
  • plugin_name - Name of the plugin registering this handler
  • handler - The handler function
ยงReturns

A unique handler ID that can be used to unregister the handler later.

ยงExample
โ“˜
let id = registry.register(
    EventType::Bell,
    100,
    "my-plugin",
    Box::new(|args| {
        println!("Bell rang!");
        EventResult::Continue
    })
);
Source

pub fn unregister(&mut self, handler_id: u64) -> bool

Unregister a handler by ID

ยงReturns

true if a handler was removed, false if no handler with that ID was found.

Source

pub fn unregister_plugin(&mut self, plugin_name: &str) -> usize

Unregister all handlers for a specific plugin

ยงReturns

The number of handlers removed.

Source

pub fn dispatch(&self, args: &EventArgs) -> Vec<EventResult>

Dispatch an event to all registered handlers

Handlers are called in priority order (highest first). If any handler returns EventResult::Stop, subsequent handlers are not called.

ยงReturns

A vector of all results returned by handlers (may be empty if no handlers are registered or if an early handler stopped processing).

Source

pub fn get_handlers(&self, event_type: &EventType) -> &[HandlerEntry]

Get all handlers for a specific event type

Returns an empty slice if no handlers are registered for that event.

Source

pub fn handler_count(&self, event_type: &EventType) -> usize

Get the number of registered handlers for an event type

Source

pub fn total_handler_count(&self) -> usize

Get the total number of registered handlers across all events

Source

pub fn clear_event(&mut self, event_type: &EventType)

Clear all handlers for a specific event type

Source

pub fn clear_all(&mut self)

Clear all handlers from the registry

Source

pub fn registered_events(&self) -> Vec<EventType>

Get a list of all event types that have registered handlers

Trait Implementationsยง

Sourceยง

impl Default for EventRegistry

Sourceยง

fn default() -> Self

Returns the โ€œdefault valueโ€ for a type. Read more

Auto Trait Implementationsยง

Blanket Implementationsยง

Sourceยง

impl<T> Any for T
where T: 'static + ?Sized,

Sourceยง

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Sourceยง

impl<T> ArchivePointee for T

Sourceยง

type ArchivedMetadata = ()

The archived version of the pointer metadata for this type.
Sourceยง

fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata

Converts some archived metadata to the pointer metadata for itself.
Sourceยง

impl<T> Borrow<T> for T
where T: ?Sized,

Sourceยง

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Sourceยง

impl<T> BorrowMut<T> for T
where T: ?Sized,

Sourceยง

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Sourceยง

impl<F, W, T, D> Deserialize<With<T, W>, D> for F
where W: DeserializeWith<F, T, D>, D: Fallible + ?Sized, F: ?Sized,

Sourceยง

fn deserialize( &self, deserializer: &mut D, ) -> Result<With<T, W>, <D as Fallible>::Error>

Deserializes using the given deserializer
Sourceยง

impl<T> From<T> for T

Sourceยง

fn from(t: T) -> T

Returns the argument unchanged.

Sourceยง

impl<T, U> Into<U> for T
where U: From<T>,

Sourceยง

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Sourceยง

impl<T> LayoutRaw for T

Sourceยง

fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>

Gets the layout of the type.
Sourceยง

impl<T> Pointee for T

Sourceยง

type Metadata = ()

The type for metadata in pointers and references to Self.
Sourceยง

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Sourceยง

type Error = Infallible

The type returned in the event of a conversion error.
Sourceยง

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Sourceยง

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Sourceยง

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Sourceยง

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Sourceยง

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Sourceยง

fn vzip(self) -> V