BusEvent

Struct BusEvent 

Source
pub struct BusEvent<ContentType, TopicId> { /* private fields */ }
Expand description

A struct that represents an event that can be sent over the event bus. The content is user-defined. Besudes the content, the event has an id, a source id, and a topic id.

Implementations§

Source§

impl<ContentType, TopicId> BusEvent<ContentType, TopicId>

Source

pub fn new( id: usize, source_id: u64, topic_id: Option<TopicId>, content: ContentType, ) -> Self

Source

pub fn get_topic_id(&self) -> &Option<TopicId>

Source

pub fn get_id(&self) -> usize

Examples found in repository?
examples/basic_game_events/player.rs (line 10)
9    fn on_event(&mut self, event: &BusEvent<Commands, TopicIds>) {
10        let event_id = event.get_id();
11        let event_source_id = event.get_source_id();
12        match event.get_content() {
13            Commands::Move { dx, dy } => {
14                println!(
15                    "[Player {}] Received event {} from ID{}: Move({}, {})",
16                    self.id, event_id, event_source_id, dx, dy
17                );
18            }
19            Commands::Atack => {
20                println!(
21                    "[Player {}] Received event {} from ID{}: Atack",
22                    self.id, event_id, event_source_id
23                );
24            }
25        }
26    }
Source

pub fn get_source_id(&self) -> u64

Examples found in repository?
examples/basic_game_events/player.rs (line 11)
9    fn on_event(&mut self, event: &BusEvent<Commands, TopicIds>) {
10        let event_id = event.get_id();
11        let event_source_id = event.get_source_id();
12        match event.get_content() {
13            Commands::Move { dx, dy } => {
14                println!(
15                    "[Player {}] Received event {} from ID{}: Move({}, {})",
16                    self.id, event_id, event_source_id, dx, dy
17                );
18            }
19            Commands::Atack => {
20                println!(
21                    "[Player {}] Received event {} from ID{}: Atack",
22                    self.id, event_id, event_source_id
23                );
24            }
25        }
26    }
Source

pub fn get_content(&self) -> &ContentType

Examples found in repository?
examples/basic_game_events/player.rs (line 12)
9    fn on_event(&mut self, event: &BusEvent<Commands, TopicIds>) {
10        let event_id = event.get_id();
11        let event_source_id = event.get_source_id();
12        match event.get_content() {
13            Commands::Move { dx, dy } => {
14                println!(
15                    "[Player {}] Received event {} from ID{}: Move({}, {})",
16                    self.id, event_id, event_source_id, dx, dy
17                );
18            }
19            Commands::Atack => {
20                println!(
21                    "[Player {}] Received event {} from ID{}: Atack",
22                    self.id, event_id, event_source_id
23                );
24            }
25        }
26    }
Source

pub fn get_mut_content(&mut self) -> &mut ContentType

Auto Trait Implementations§

§

impl<ContentType, TopicId> Freeze for BusEvent<ContentType, TopicId>
where ContentType: Freeze, TopicId: Freeze,

§

impl<ContentType, TopicId> RefUnwindSafe for BusEvent<ContentType, TopicId>
where ContentType: RefUnwindSafe, TopicId: RefUnwindSafe,

§

impl<ContentType, TopicId> Send for BusEvent<ContentType, TopicId>
where ContentType: Send, TopicId: Send,

§

impl<ContentType, TopicId> Sync for BusEvent<ContentType, TopicId>
where ContentType: Sync, TopicId: Sync,

§

impl<ContentType, TopicId> Unpin for BusEvent<ContentType, TopicId>
where ContentType: Unpin, TopicId: Unpin,

§

impl<ContentType, TopicId> UnwindSafe for BusEvent<ContentType, TopicId>
where ContentType: UnwindSafe, TopicId: UnwindSafe,

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> 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<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, 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.