pub struct GameEvent<'a> { /* private fields */ }Expand description
Represents a game event with its name and values.
Game events are structured in-game occurrences. Each event has a name and a set of named values.
§Examples
§Accessing event data
use source2_demo::prelude::*;
// Get the event name
println!("Event: {}", ge.name());
// Iterate all key-value pairs
for (key, value) in ge.iter() {
println!("{}: {:?}", key, value);
}
// Get a specific value
let player_id: i32 = ge.get_value("player_id")?.try_into()?;Implementations§
Source§impl<'a> GameEvent<'a>
impl<'a> GameEvent<'a>
Sourcepub fn iter(&self) -> impl Iterator<Item = (&str, &EventValue)>
pub fn iter(&self) -> impl Iterator<Item = (&str, &EventValue)>
Returns an iterator over all key-value pairs in the event.
§Examples
use source2_demo::prelude::*;
for (key, value) in ge.iter() {
println!("{}: {:?}", key, value);
}Sourcepub fn get_value(&self, key: &str) -> Result<&EventValue, GameEventError>
pub fn get_value(&self, key: &str) -> Result<&EventValue, GameEventError>
Gets the value for a specific key.
§Arguments
key- The name of the key to look up
§Errors
Returns GameEventError::UnknownKey if the key doesn’t exist for this event.
§Examples
use source2_demo::prelude::*;
// Get a value and convert it
let player_id: i32 = ge.get_value("player_id")?.try_into()?;
let hero_name: String = ge.get_value("hero_name")?.try_into()?;Trait Implementations§
Auto Trait Implementations§
impl<'a> Freeze for GameEvent<'a>
impl<'a> RefUnwindSafe for GameEvent<'a>
impl<'a> !Send for GameEvent<'a>
impl<'a> !Sync for GameEvent<'a>
impl<'a> Unpin for GameEvent<'a>
impl<'a> UnsafeUnpin for GameEvent<'a>
impl<'a> UnwindSafe for GameEvent<'a>
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