Skip to main content

JsString

Struct JsString 

Source
pub struct JsString { /* private fields */ }
Expand description

An immutable string, stored on the GC heap.

The content is a Wtf8; the wrapper exists so a Value can hold a Gc handle rather than the bytes.

Implementations§

Source§

impl JsString

Source

pub fn new(text: impl Into<String>) -> JsString

Wrap text.

Source

pub fn from_wtf8(text: Wtf8) -> JsString

Wrap WTF-8 that is already encoded.

Source

pub fn units_cached(&self) -> Rc<Vec<u16>>

The code units, decoding once and remembering the result.

Source

pub fn code_unit_at(&self, index: usize) -> Option<u16>

The code unit at index, in O(1) once the cache is warm.

Source

pub fn wtf8(&self) -> &Wtf8

The string’s bytes.

Source

pub fn as_str(&self) -> Option<&str>

The text, when it has no unpaired surrogate.

Source

pub fn to_string_lossy(&self) -> Cow<'_, str>

The text with unpaired surrogates replaced by U+FFFD.

Source

pub fn to_units(&self) -> Vec<u16>

The UTF-16 code units.

Source

pub fn utf16_len(&self) -> usize

Length in UTF-16 code units, which is what String.prototype.length and the string indexing rules count.

Trait Implementations§

Source§

impl Debug for JsString

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Trace for JsString

Source§

fn trace(&self, _tracer: &mut Tracer<'_>)

Report every Gc owned by self to tracer.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.