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>
impl<ContentType, TopicId> BusEvent<ContentType, TopicId>
pub fn new( id: usize, source_id: u64, topic_id: Option<TopicId>, content: ContentType, ) -> Self
pub fn get_topic_id(&self) -> &Option<TopicId>
Sourcepub fn get_id(&self) -> usize
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 }Sourcepub fn get_source_id(&self) -> u64
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 }Sourcepub fn get_content(&self) -> &ContentType
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 }pub fn get_mut_content(&mut self) -> &mut ContentType
Auto Trait Implementations§
impl<ContentType, TopicId> Freeze for BusEvent<ContentType, TopicId>
impl<ContentType, TopicId> RefUnwindSafe for BusEvent<ContentType, TopicId>where
ContentType: RefUnwindSafe,
TopicId: RefUnwindSafe,
impl<ContentType, TopicId> Send for BusEvent<ContentType, TopicId>
impl<ContentType, TopicId> Sync for BusEvent<ContentType, TopicId>
impl<ContentType, TopicId> Unpin for BusEvent<ContentType, TopicId>
impl<ContentType, TopicId> UnwindSafe for BusEvent<ContentType, TopicId>where
ContentType: UnwindSafe,
TopicId: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more