Skip to main content

GameEvent

Struct GameEvent 

Source
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>

Source

pub fn id(&self) -> i32

Returns the event’s numeric ID.

Source

pub fn name(&self) -> &str

Returns the event’s name.

Event names are strings

Source

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);
}
Source

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§

Source§

impl Display for GameEvent<'_>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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> 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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
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.