Struct ClassId
pub struct ClassId { /* private fields */ }
Expand description
Globally unique ID of a class registered with Godot.
This struct implements Copy
and is very cheap to copy and compare with other ClassId
s.
ClassId
can also be used to obtain the class name, which is cached globally, not per-instance. Note that it holds the Godot name,
not the Rust name – they sometimes differ, e.g. Godot CSGMesh3D
vs Rust CsgMesh3D
.
You can access existing classes’ ID using GodotClass::class_id()
.
If you need to create your own class ID, use new_cached()
.
§Ordering
ClassId
s are not ordered lexicographically, and the ordering relation is not stable across multiple runs of your
application. When lexicographical order is needed, it’s possible to convert this type to GString
or String
. Note that
StringName
does not implement Ord
, and its Godot comparison operators are not lexicographical either.
Implementations§
§impl ClassId
impl ClassId
pub fn new_cached<T>(init_fn: impl FnOnce() -> String) -> ClassIdwhere
T: GodotClass,
pub fn new_cached<T>(init_fn: impl FnOnce() -> String) -> ClassIdwhere
T: GodotClass,
Construct a new class name.
You should typically only need this when implementing GodotClass
manually, without #[derive(GodotClass)]
, and overriding
class_id()
. To access an existing type’s class name, use <T as GodotClass>::class_id()
.
This function is expensive the first time it called for a given T
, but will be cached for subsequent calls. It can make sense to
store the result in a static
, to further reduce lookup times, but it’s not required.
We discourage calling this function from different places for the same T
. But if you do so, init_fn
must return the same string.
§Panics
If the string is not ASCII and the Godot version is older than 4.4. From Godot 4.4 onwards, class names can be Unicode.
pub fn to_gstring(&self) -> GString
pub fn to_gstring(&self) -> GString
Returns the class name as a GString
.
pub fn to_string_name(&self) -> StringName
pub fn to_string_name(&self) -> StringName
Returns the class name as a StringName
.
pub fn to_cow_str(&self) -> Cow<'static, str>
pub fn to_cow_str(&self) -> Cow<'static, str>
Returns an owned or borrowed str
representing the class name.