Struct gdnative_core::core_types::string::GodotString[][src]

pub struct GodotString(_);

Godot's reference-counted string type.

This is the Rust binding of GDScript's String type. It represents the native string class used within the Godot engine, and as such has different memory layout and characteristics than std::string::String.

GodotString is reference-counted like most types in godot-rust. Thus, its clone() method does not return a copy of the string, but simply another instance which shares the same backing string. Furthermore, GodotString is immutable and does not offer any write APIs. If you need to modify Godot strings, convert them to Rust strings, perform the modifications and convert back. In GDScript, strings have copy-on-write semantics, which guarantees that GodotString instances in Rust are independent of their GDScript counterparts. A modification of a string in GDScript (which was previously passed to Rust) will not be reflected in Rust.

When interfacing with the Godot engine API through godot-rust, you often have the choice between std::string::String and gdnative::core_types::GodotString. In user methods that are exposed to Godot through the #[export] macro, both types can be used as parameters and return types, and any conversions are done transparently. For auto-generated binding APIs in gdnative::api, return types are GodotString, but parameters are declared impl Into<GodotString>, allowing String or &str to be passed. In addition, the two types can always be explicitly converted using GodotString::from_str() and GodotString::display/to_string().

As a general guideline, use GodotString if:

  • your strings are very large, so you can avoid copying them
  • you need specific operations only available in Godot (e.g. sha256_text(), c_escape(), ...)
  • you primarily pass them between different Godot APIs, without string processing in user code

Use Rust's String if:

  • you need to modify the string
  • you would like to decouple part of your code from Godot (e.g. independent game logic, standalone tests)
  • you want a standard type for interoperability with third-party code (e.g. regex crate)
  • you have a large number of method calls per string instance (which are more expensive due to indirectly calling into Godot)
  • you need UTF-8 encoding (GodotString's encoding is platform-dependent and unspecified)

Implementations

impl GodotString[src]

pub fn new() -> Self[src]

pub fn from_str<S>(s: S) -> Self where
    S: AsRef<str>, 
[src]

pub fn len(&self) -> usize[src]

pub fn is_empty(&self) -> bool[src]

pub fn is_numeric(&self) -> bool[src]

pub fn is_valid_float(&self) -> bool[src]

pub fn is_valid_html_color(&self) -> bool[src]

pub fn is_valid_identifier(&self) -> bool[src]

pub fn is_valid_integer(&self) -> bool[src]

pub fn is_valid_ip_address(&self) -> bool[src]

pub fn is_resource_file(&self) -> bool[src]

pub fn is_absolute_path(&self) -> bool[src]

pub fn is_relative_path(&self) -> bool[src]

pub fn to_f32(&self) -> f32[src]

pub fn to_f64(&self) -> f64[src]

pub fn to_i32(&self) -> i32[src]

pub fn u32_hash(&self) -> u32[src]

pub fn u64_hash(&self) -> u64[src]

pub fn hex_to_int(&self) -> i32[src]

pub fn hex_to_int_without_prefix(&self) -> i32[src]

pub fn camelcase_to_underscore(&self) -> Self[src]

pub fn camelcase_to_underscore_lowercased(&self) -> Self[src]

pub fn capitalize(&self) -> Self[src]

pub fn to_lowercase(&self) -> Self[src]

pub fn to_uppercase(&self) -> Self[src]

pub fn get_file(&self) -> Self[src]

pub fn get_base_dir(&self) -> Self[src]

pub fn get_basename(&self) -> Self[src]

pub fn get_extension(&self) -> Self[src]

pub fn simplify_path(&self) -> Self[src]

pub fn sha256_text(&self) -> Self[src]

pub fn md5_text(&self) -> Self[src]

pub fn c_escape(&self) -> Self[src]

pub fn c_escape_multiline(&self) -> Self[src]

pub fn c_unescape(&self) -> Self[src]

pub fn http_escape(&self) -> Self[src]

pub fn http_unescape(&self) -> Self[src]

pub fn json_escape(&self) -> Self[src]

pub fn xml_escape(&self) -> Self[src]

pub fn xml_escape_with_quotes(&self) -> Self[src]

pub fn xml_unescape(&self) -> Self[src]

pub fn percent_decode(&self) -> Self[src]

pub fn percent_encode(&self) -> Self[src]

pub fn is_valid_hex_number(&self, with_prefix: bool) -> bool[src]

pub fn begins_with(&self, s: &GodotString) -> bool[src]

pub fn ends_with(&self, s: &GodotString) -> bool[src]

pub fn begins_with_c_str(&self, s: &CStr) -> bool[src]

pub fn sub_string(&self, range: Range<usize>) -> Self[src]

pub fn find(&self, what: &GodotString) -> i32[src]

pub fn find_from(&self, what: &GodotString, from: i32) -> i32[src]

pub fn find_last(&self, what: &GodotString) -> i32[src]

Trait Implementations

impl Add<&'_ GodotString> for &GodotString[src]

type Output = GodotString

The resulting type after applying the + operator.

impl Add<GodotString> for GodotString[src]

type Output = GodotString

The resulting type after applying the + operator.

impl<S> Add<S> for &GodotString where
    S: AsRef<str>, 
[src]

type Output = GodotString

The resulting type after applying the + operator.

impl AddAssign<&'_ GodotString> for GodotString[src]

AddAssign implementations copy the strings' contents since GodotString is immutable.

impl AddAssign<GodotString> for GodotString[src]

AddAssign implementations copy the strings' contents since GodotString is immutable.

impl<S> AddAssign<S> for GodotString where
    S: AsRef<str>, 
[src]

AddAssign implementations copy the strings' contents since GodotString is immutable.

impl Clone for GodotString[src]

impl Debug for GodotString[src]

impl Default for GodotString[src]

impl Display for GodotString[src]

impl Drop for GodotString[src]

impl Element for GodotString[src]

type SysArray = godot_pool_string_array

type SysReadAccess = godot_pool_string_array_read_access

type SysWriteAccess = godot_pool_string_array_write_access

type SysTy = godot_string

type SysRefTy = *const godot_string

impl Eq for GodotString[src]

impl Export for GodotString[src]

type Hint = StringHint

A type-specific hint type that is valid for the type being exported.

impl From<GodotString> for NodePath[src]

impl<S> From<S> for GodotString where
    S: AsRef<str>, 
[src]

impl FromVariant for GodotString[src]

impl Hash for GodotString[src]

impl Index<usize> for GodotString[src]

The index operator provides a low-level view of characters in Godot's native encoding that doesn't always correspond to Unicode code points one-to-one. This operation goes through FFI. For intensive string operations, consider converting to a Rust String first to avoid this cost.

type Output = GodotChar

The returned type after indexing.

impl Into<GodotString> for NodePath[src]

impl NewRef for GodotString[src]

impl Ord for GodotString[src]

impl PartialEq<GodotString> for GodotString[src]

impl PartialOrd<GodotString> for GodotString[src]

impl ToVariant for GodotString[src]

impl ToVariantEq for GodotString[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> CallHasher for T where
    T: Hash + ?Sized
[src]

impl<Q, K> Equivalent<K> for Q where
    K: Borrow<Q> + ?Sized,
    Q: Eq + ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> OwnedToVariant for T where
    T: ToVariant
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.