[−][src]Struct rhai::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.
Example
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) -> &str
1.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) -> usize
1.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]ⓘ
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) -> usize
1.0.0[src]
Returns the length of this String
, in bytes, not char
s 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) -> bool
1.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.
fn add(self, rhs: Self) -> Self::Output
[src]
impl<'_> Add<&'_ str> for ImmutableString
[src]
type Output = Self
The resulting type after applying the +
operator.
fn add(self, rhs: &str) -> Self::Output
[src]
impl<'_, '_> Add<&'_ str> for &'_ ImmutableString
[src]
type Output = ImmutableString
The resulting type after applying the +
operator.
fn add(self, rhs: &str) -> Self::Output
[src]
impl Add<ImmutableString> for ImmutableString
[src]
type Output = Self
The resulting type after applying the +
operator.
fn add(self, rhs: Self) -> Self::Output
[src]
impl Add<String> for ImmutableString
[src]
type Output = Self
The resulting type after applying the +
operator.
fn add(self, rhs: String) -> Self::Output
[src]
impl<'_> Add<String> for &'_ ImmutableString
[src]
type Output = ImmutableString
The resulting type after applying the +
operator.
fn add(self, rhs: String) -> Self::Output
[src]
impl Add<char> for ImmutableString
[src]
type Output = Self
The resulting type after applying the +
operator.
fn add(self, rhs: char) -> Self::Output
[src]
impl<'_> Add<char> for &'_ ImmutableString
[src]
type Output = ImmutableString
The resulting type after applying the +
operator.
fn add(self, rhs: char) -> Self::Output
[src]
impl<'_> AddAssign<&'_ ImmutableString> for ImmutableString
[src]
fn add_assign(&mut self, rhs: &ImmutableString)
[src]
impl<'_> AddAssign<&'_ str> for ImmutableString
[src]
fn add_assign(&mut self, rhs: &str)
[src]
impl AddAssign<ImmutableString> for ImmutableString
[src]
fn add_assign(&mut self, rhs: ImmutableString)
[src]
impl AddAssign<char> for ImmutableString
[src]
fn add_assign(&mut self, rhs: char)
[src]
impl AsRef<String> for ImmutableString
[src]
impl Borrow<String> for ImmutableString
[src]
impl Borrow<str> for ImmutableString
[src]
impl Clone for ImmutableString
[src]
fn clone(&self) -> ImmutableString
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl Debug for ImmutableString
[src]
impl Default for ImmutableString
[src]
fn default() -> ImmutableString
[src]
impl Deref for ImmutableString
[src]
impl Display for ImmutableString
[src]
impl Eq for ImmutableString
[src]
impl<'_> From<&'_ str> for ImmutableString
[src]
impl From<Box<String, Global>> for ImmutableString
[src]
impl From<ImmutableString> for String
[src]
fn from(value: ImmutableString) -> Self
[src]
impl From<String> for ImmutableString
[src]
impl<'a> FromIterator<&'a char> for ImmutableString
[src]
fn from_iter<T: IntoIterator<Item = &'a char>>(iter: T) -> Self
[src]
impl<'a> FromIterator<&'a str> for ImmutableString
[src]
fn from_iter<T: IntoIterator<Item = &'a str>>(iter: T) -> Self
[src]
impl<'a> FromIterator<String> for ImmutableString
[src]
fn from_iter<T: IntoIterator<Item = String>>(iter: T) -> Self
[src]
impl FromIterator<char> for ImmutableString
[src]
fn from_iter<T: IntoIterator<Item = char>>(iter: T) -> Self
[src]
impl FromStr for ImmutableString
[src]
type Err = ()
The associated error which can be returned from parsing.
fn from_str(s: &str) -> Result<Self, Self::Err>
[src]
impl Hash for ImmutableString
[src]
fn hash<__H: Hasher>(&self, state: &mut __H)
[src]
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
impl Ord for ImmutableString
[src]
fn cmp(&self, other: &ImmutableString) -> Ordering
[src]
#[must_use]fn max(self, other: Self) -> Self
1.21.0[src]
#[must_use]fn min(self, other: Self) -> Self
1.21.0[src]
#[must_use]fn clamp(self, min: Self, max: Self) -> Self
[src]
impl PartialEq<ImmutableString> for ImmutableString
[src]
fn eq(&self, other: &ImmutableString) -> bool
[src]
fn ne(&self, other: &ImmutableString) -> bool
[src]
impl PartialEq<ImmutableString> for str
[src]
fn eq(&self, other: &ImmutableString) -> bool
[src]
#[must_use]fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
impl PartialEq<ImmutableString> for String
[src]
fn eq(&self, other: &ImmutableString) -> bool
[src]
#[must_use]fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
impl<S: AsRef<str>> PartialEq<S> for ImmutableString
[src]
impl PartialOrd<ImmutableString> for ImmutableString
[src]
fn partial_cmp(&self, other: &ImmutableString) -> Option<Ordering>
[src]
fn lt(&self, other: &ImmutableString) -> bool
[src]
fn le(&self, other: &ImmutableString) -> bool
[src]
fn gt(&self, other: &ImmutableString) -> bool
[src]
fn ge(&self, other: &ImmutableString) -> bool
[src]
impl PartialOrd<ImmutableString> for str
[src]
fn partial_cmp(&self, other: &ImmutableString) -> Option<Ordering>
[src]
#[must_use]fn lt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]fn le(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]fn gt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]fn ge(&self, other: &Rhs) -> bool
1.0.0[src]
impl PartialOrd<ImmutableString> for String
[src]
fn partial_cmp(&self, other: &ImmutableString) -> Option<Ordering>
[src]
#[must_use]fn lt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]fn le(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]fn gt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]fn ge(&self, other: &Rhs) -> bool
1.0.0[src]
impl<S: AsRef<str>> PartialOrd<S> for ImmutableString
[src]
fn partial_cmp(&self, other: &S) -> Option<Ordering>
[src]
#[must_use]fn lt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]fn le(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]fn gt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]fn ge(&self, other: &Rhs) -> bool
1.0.0[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.
fn try_from(value: ImmutableString) -> Result<Self, Self::Error>
[src]
Auto Trait Implementations
impl !RefUnwindSafe for ImmutableString
impl !Send for ImmutableString
impl !Sync for ImmutableString
impl Unpin for ImmutableString
impl UnwindSafe for ImmutableString
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow(&self) -> &TⓘNotable traits for &'_ mut W
impl<'_, W> Write for &'_ mut W where
W: Write + ?Sized, impl<'_, R> Read for &'_ mut R where
R: Read + ?Sized, impl<'_, I> Iterator for &'_ mut I where
I: Iterator + ?Sized, type Item = <I as Iterator>::Item;impl<'_, F> Future for &'_ mut F where
F: Unpin + Future + ?Sized, type Output = <F as Future>::Output;
[src]
Notable traits for &'_ mut W
impl<'_, W> Write for &'_ mut W where
W: Write + ?Sized, impl<'_, R> Read for &'_ mut R where
R: Read + ?Sized, impl<'_, I> Iterator for &'_ mut I where
I: Iterator + ?Sized, type Item = <I as Iterator>::Item;impl<'_, F> Future for &'_ mut F where
F: Unpin + Future + ?Sized, type Output = <F as Future>::Output;
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut TⓘNotable traits for &'_ mut W
impl<'_, W> Write for &'_ mut W where
W: Write + ?Sized, impl<'_, R> Read for &'_ mut R where
R: Read + ?Sized, impl<'_, I> Iterator for &'_ mut I where
I: Iterator + ?Sized, type Item = <I as Iterator>::Item;impl<'_, F> Future for &'_ mut F where
F: Unpin + Future + ?Sized, type Output = <F as Future>::Output;
[src]
Notable traits for &'_ mut W
impl<'_, W> Write for &'_ mut W where
W: Write + ?Sized, impl<'_, R> Read for &'_ mut R where
R: Read + ?Sized, impl<'_, I> Iterator for &'_ mut I where
I: Iterator + ?Sized, type Item = <I as Iterator>::Item;impl<'_, F> Future for &'_ mut F where
F: Unpin + Future + ?Sized, type Output = <F as Future>::Output;
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,