Skip to main content

Classes

Struct Classes 

Source
pub struct Classes { /* private fields */ }
Expand description

Container for all entity classes in a replay.

Classes define the types of entities that exist in the game. Each entity belongs to a class which specifies:

  • What properties it has
  • How those properties are encoded
  • The class name (e.g., “CDOTA_Unit_Hero_Axe”)

§Examples

§Iterating all classes

use source2_demo::prelude::*;

for class in ctx.classes().iter() {
    println!("Class ID {}: {}", class.id(), class.name());
}

§Finding a specific class

use source2_demo::prelude::*;

// Get by class name
let hero_class = ctx.classes().get_by_name("CDOTA_Unit_Hero_Axe")?;
println!("Found class: {}", hero_class.name());

// Get by ID
let class = ctx.classes().get_by_id(42)?;

Implementations§

Source§

impl Classes

Source

pub fn iter(&self) -> impl Iterator<Item = &Class>

Returns an iterator over all classes.

This allows you to discover all entity types in the replay.

Source

pub fn get_by_id(&self, id: usize) -> Result<&Class, ClassError>

Gets a class by its numeric ID.

§Arguments
  • id - The numeric class ID
§Errors

Returns ClassError::ClassNotFoundById if no class with the given ID exists.

§Examples
use source2_demo::prelude::*;

let class = ctx.classes().get_by_id(42)?;
println!("Class name: {}", class.name());
Source

pub fn get_by_name(&self, name: &str) -> Result<&Class, ClassError>

Gets a class by its name.

This is the most common way to find entity classes since you typically know the class name you’re looking for (e.g., “CDOTA_Unit_Hero_Axe”).

§Arguments
  • name - The class name (case-sensitive, e.g., “CDOTA_PlayerResource”)
§Errors

Returns ClassError::ClassNotFoundByName if no class with the given name exists.

§Examples
use source2_demo::prelude::*;

// Find hero class
let hero_class = ctx.classes().get_by_name("CDOTA_Unit_Hero_Axe")?;

// Find player resource class
let resource = ctx.classes().get_by_name("CDOTA_PlayerResource")?;

Trait Implementations§

Source§

impl Default for Classes

Source§

fn default() -> Classes

Returns the “default value” for a type. Read more
Source§

impl Display for Classes

Source§

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

Formats the value using the given formatter. 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> 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.