Skip to main content

GodotStringExt

Trait GodotStringExt 

pub trait GodotStringExt {
    // Required methods
    fn to_gstring(&self) -> GString;
    fn to_string_name(&self) -> StringName;
    fn to_node_path(&self) -> NodePath;
}
Expand description

Extension trait for converting to Godot string types.

Provides types like &str and String with “extension functions” to convert to one of the Godot string types.

An explicitly named val.to_gstring() method has several advantages over the From trait (which may be phased out over time):

  • Compared to GString::from(&val), it is shorter and can be used in fluent expressions such as val.replace(...).to_gstring().
  • Compared to val.into(), it makes the conversion more explicit by naming the type, and never runs into type-inference problems (the into() function requires an explicit type declaration somewhere).

Required Methods§

fn to_gstring(&self) -> GString

Convert to a GString.

fn to_string_name(&self) -> StringName

Convert to a StringName.

fn to_node_path(&self) -> NodePath

Convert to a NodePath.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

§

impl GodotStringExt for &[char]

§

impl GodotStringExt for &str

§

impl GodotStringExt for String

Implementors§