[−][src]Struct ustr::Ustr
A handle representing a string in the global string cache.
To use, create one using Ustr::from
or the ustr
function. You can freely
copy, destroy or send Ustrs to other threads: the underlying string is
always valid in memory (and is never destroyed).
Methods
impl Ustr
[src]
pub fn from(string: &str) -> Ustr
[src]
Create a new Ustr from the given &str.
You can also use the ustr function
use ustr::{Ustr, ustr as u}; let u1 = Ustr::from("the quick brown fox"); let u2 = u("the quick brown fox"); assert_eq!(u1, u2); assert_eq!(ustr::num_entries(), 1);
pub fn as_str(&self) -> &str
[src]
Get the cached string as a &str
use ustr::ustr as u; let u_fox = u("the quick brown fox"); let words: Vec<&str> = u_fox.as_str().split_whitespace().collect(); assert_eq!(words, ["the", "quick", "brown", "fox"]);
pub unsafe fn as_char_ptr(&self) -> *const c_char
[src]
Get the cached string as a C char*.
This includes the null terminator so is safe to pass straight to FFI.
use ustr::ustr as u; let u_fox = u("the quick brown fox"); let len = unsafe { libc::strlen(u_fox.as_char_ptr()) }; assert_eq!(len, 19);
Safety
This is just passing a raw byte array with a null terminator to C. If your source string contains non-ascii bytes then this will pass them straight along with no checking. The string is immutable. That means that if you modify it across the FFI boundary then all sorts of terrible things will happen.
pub fn len(&self) -> usize
[src]
Get the length (in bytes) of this string.
pub fn precomputed_hash(&self) -> u64
[src]
Get the precomputed hash for this string
pub fn to_owned(&self) -> String
[src]
Get an owned String copy of this string.
Trait Implementations
impl AsRef<str> for Ustr
[src]
impl Clone for Ustr
[src]
impl Copy for Ustr
[src]
impl Debug for Ustr
[src]
impl Display for Ustr
[src]
impl Eq for Ustr
[src]
impl<'_> From<&'_ str> for Ustr
[src]
impl From<String> for Ustr
[src]
impl Hash for Ustr
[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<'_> PartialEq<&'_ str> for Ustr
[src]
impl PartialEq<String> for Ustr
[src]
impl PartialEq<Ustr> for Ustr
[src]
impl PartialOrd<Ustr> for Ustr
[src]
fn partial_cmp(&self, other: &Ustr) -> Option<Ordering>
[src]
fn lt(&self, other: &Ustr) -> bool
[src]
fn le(&self, other: &Ustr) -> bool
[src]
fn gt(&self, other: &Ustr) -> bool
[src]
fn ge(&self, other: &Ustr) -> bool
[src]
impl Send for Ustr
[src]
impl StructuralPartialEq for Ustr
[src]
impl Sync for Ustr
[src]
Auto Trait Implementations
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,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
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.
fn to_owned(&self) -> T
[src]
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.
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>,