[][src]Struct rhai::ImmutableString

pub struct ImmutableString(_);

The system immutable string type.

An ImmutableString wraps an Rc<String> (or Arc<String> under the sync feature) so that it can be simply shared and not cloned.

Examples

use rhai::ImmutableString;

let s1: ImmutableString = "hello".into();

// No actual cloning of the string is involved below.
let s2 = s1.clone();
let s3 = s2.clone();

assert_eq!(s1, s2);

// Clones the underlying string (because it is already shared) and extracts it.
let mut s: String = s1.into_owned();

// Changing the clone has no impact on the previously shared version.
s.push_str(", world!");

// The old version still exists.
assert_eq!(s2, s3);
assert_eq!(s2.as_str(), "hello");

// Not equals!
assert_ne!(s2.as_str(), s.as_str());
assert_eq!(s, "hello, world!");

Implementations

impl ImmutableString[src]

pub fn into_owned(self) -> String[src]

Consume the ImmutableString and convert it into a String. If there are other references to the same string, a cloned copy is returned.

pub fn make_mut(&mut self) -> &mut String[src]

Make sure that the ImmutableString is unique (i.e. no other outstanding references). Then return a mutable reference to the String.

Methods from Deref<Target = String>

pub fn as_str(&self) -> &str1.7.0[src]

Extracts a string slice containing the entire String.

Examples

Basic usage:

let s = String::from("foo");

assert_eq!("foo", s.as_str());

pub fn capacity(&self) -> usize1.0.0[src]

Returns this String's capacity, in bytes.

Examples

Basic usage:

let s = String::with_capacity(10);

assert!(s.capacity() >= 10);

pub fn as_bytes(&self) -> &[u8]

Notable traits for &'_ mut [u8]

impl<'_> Write for &'_ mut [u8]impl<'_> Read for &'_ [u8]
1.0.0[src]

Returns a byte slice of this String's contents.

The inverse of this method is from_utf8.

Examples

Basic usage:

let s = String::from("hello");

assert_eq!(&[104, 101, 108, 108, 111], s.as_bytes());

pub fn len(&self) -> usize1.0.0[src]

Returns the length of this String, in bytes, not chars or graphemes. In other words, it may not be what a human considers the length of the string.

Examples

Basic usage:

let a = String::from("foo");
assert_eq!(a.len(), 3);

let fancy_f = String::from("ƒoo");
assert_eq!(fancy_f.len(), 4);
assert_eq!(fancy_f.chars().count(), 3);

pub fn is_empty(&self) -> bool1.0.0[src]

Returns true if this String has a length of zero, and false otherwise.

Examples

Basic usage:

let mut v = String::new();
assert!(v.is_empty());

v.push('a');
assert!(!v.is_empty());

Trait Implementations

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

type Output = ImmutableString

The resulting type after applying the + operator.

impl<'_> Add<&'_ str> for ImmutableString[src]

type Output = Self

The resulting type after applying the + operator.

impl<'_, '_> Add<&'_ str> for &'_ ImmutableString[src]

type Output = ImmutableString

The resulting type after applying the + operator.

impl Add<ImmutableString> for ImmutableString[src]

type Output = Self

The resulting type after applying the + operator.

impl Add<String> for ImmutableString[src]

type Output = Self

The resulting type after applying the + operator.

impl<'_> Add<String> for &'_ ImmutableString[src]

type Output = ImmutableString

The resulting type after applying the + operator.

impl Add<char> for ImmutableString[src]

type Output = Self

The resulting type after applying the + operator.

impl<'_> Add<char> for &'_ ImmutableString[src]

type Output = ImmutableString

The resulting type after applying the + operator.

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

impl<'_> AddAssign<&'_ str> for ImmutableString[src]

impl AddAssign<ImmutableString> for ImmutableString[src]

impl AddAssign<char> for ImmutableString[src]

impl AsRef<String> for ImmutableString[src]

impl Borrow<String> for ImmutableString[src]

impl Borrow<str> for ImmutableString[src]

impl Clone for ImmutableString[src]

impl Debug for ImmutableString[src]

impl Default for ImmutableString[src]

impl Deref for ImmutableString[src]

type Target = String

The resulting type after dereferencing.

impl Display for ImmutableString[src]

impl Eq for ImmutableString[src]

impl<'_> From<&'_ str> for ImmutableString[src]

impl From<Box<String>> for ImmutableString[src]

impl From<ImmutableString> for String[src]

impl From<String> for ImmutableString[src]

impl<'a> FromIterator<&'a char> for ImmutableString[src]

impl<'a> FromIterator<&'a str> for ImmutableString[src]

impl<'a> FromIterator<String> for ImmutableString[src]

impl FromIterator<char> for ImmutableString[src]

impl FromStr for ImmutableString[src]

type Err = ()

The associated error which can be returned from parsing.

impl Hash for ImmutableString[src]

impl Ord for ImmutableString[src]

impl PartialEq<ImmutableString> for ImmutableString[src]

impl PartialEq<ImmutableString> for str[src]

impl PartialEq<ImmutableString> for String[src]

impl<S: AsRef<str>> PartialEq<S> for ImmutableString[src]

impl PartialOrd<ImmutableString> for ImmutableString[src]

impl PartialOrd<ImmutableString> for str[src]

impl PartialOrd<ImmutableString> for String[src]

impl<S: AsRef<str>> PartialOrd<S> for ImmutableString[src]

impl StructuralEq for ImmutableString[src]

impl StructuralPartialEq for ImmutableString[src]

impl TryFrom<ImmutableString> for FnPtr[src]

type Error = Box<EvalAltResult>

The type returned in the event of a conversion error.

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> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[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.