Struct ClassName
pub struct ClassName { /* private fields */ }
Expand description
Name of a class registered with Godot.
Holds the Godot name, not the Rust name (they sometimes differ, e.g. Godot CSGMesh3D
vs Rust CsgMesh3D
).
This struct is very cheap to copy. The actual names are cached globally.
If you need to create your own class name, use new_cached()
.
§Ordering
ClassName
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
.
Implementations§
§impl ClassName
impl ClassName
pub fn new_cached<T>(init_fn: impl FnOnce() -> String) -> ClassNamewhere
T: GodotClass,
pub fn new_cached<T>(init_fn: impl FnOnce() -> String) -> ClassNamewhere
T: GodotClass,
Construct a new class name.
This is expensive the first time it called for a given T
, but will be cached for subsequent calls.
It is not specified when exactly init_fn
is invoked. However, it must return the same value for the same T
. Generally, we expect
to keep the invocations limited, so you can use more expensive construction in the closure.
§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
Converts the class name to a GString
.
pub fn to_string_name(&self) -> StringName
pub fn to_string_name(&self) -> StringName
Converts the class name to 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
.