pub struct JsStr<'a> { /* private fields */ }Expand description
This is equivalent to Rust’s &str.
Implementations§
Source§impl<'a> JsStr<'a>
impl<'a> JsStr<'a>
Sourcepub const fn latin1(value: &'a [u8]) -> JsStr<'a>
pub const fn latin1(value: &'a [u8]) -> JsStr<'a>
Creates a JsStr from codepoints that can fit in a u8.
Sourcepub const fn variant(self) -> JsStrVariant<'a>
pub const fn variant(self) -> JsStrVariant<'a>
Return the inner JsStrVariant varient of the JsStr.
Sourcepub fn trim_start(self) -> JsStr<'a>
pub fn trim_start(self) -> JsStr<'a>
Trims all leading space.
Sourcepub fn get<I>(self, index: I) -> Option<<I as JsSliceIndex<'a>>::Value>where
I: JsSliceIndex<'a>,
pub fn get<I>(self, index: I) -> Option<<I as JsSliceIndex<'a>>::Value>where
I: JsSliceIndex<'a>,
Returns an element or subslice depending on the type of index, otherwise None.
Sourcepub fn get_expect<I>(&self, index: I) -> <I as JsSliceIndex<'a>>::Valuewhere
I: JsSliceIndex<'a>,
pub fn get_expect<I>(&self, index: I) -> <I as JsSliceIndex<'a>>::Valuewhere
I: JsSliceIndex<'a>,
Sourcepub unsafe fn get_unchecked<I>(self, index: I) -> <I as JsSliceIndex<'a>>::Valuewhere
I: JsSliceIndex<'a>,
pub unsafe fn get_unchecked<I>(self, index: I) -> <I as JsSliceIndex<'a>>::Valuewhere
I: JsSliceIndex<'a>,
Returns an element or subslice depending on the type of index, without doing bounds check.
§Safety
Caller must ensure the index is not out of bounds
Sourcepub fn starts_with(&self, needle: JsStr<'_>) -> bool
pub fn starts_with(&self, needle: JsStr<'_>) -> bool
Returns true if needle is a prefix of the JsStr.
Sourcepub fn ends_with(&self, needle: JsStr<'_>) -> bool
pub fn ends_with(&self, needle: JsStr<'_>) -> bool
Returns true if needle is a suffix of the JsStr.
Sourcepub fn index_of(
&self,
search_value: JsStr<'_>,
from_index: usize,
) -> Option<usize>
pub fn index_of( &self, search_value: JsStr<'_>, from_index: usize, ) -> Option<usize>
Sourcepub fn code_point_at(&self, position: usize) -> CodePoint
pub fn code_point_at(&self, position: usize) -> CodePoint
Abstract operation CodePointAt( string, position ).
The abstract operation CodePointAt takes arguments string (a String) and position (a
non-negative integer) and returns a Record with fields [[CodePoint]] (a code point),
[[CodeUnitCount]] (a positive integer), and [[IsUnpairedSurrogate]] (a Boolean). It
interprets string as a sequence of UTF-16 encoded code points, as described in 6.1.4, and reads
from it a single code point starting with the code unit at index position.
More information:
§Panics
If position is smaller than size of string.
Sourcepub fn code_points(&self) -> impl Iterator<Item = CodePoint> + Clone + use<'a>
pub fn code_points(&self) -> impl Iterator<Item = CodePoint> + Clone + use<'a>
Gets an iterator of all the Unicode codepoints of a JsStr.
Sourcepub fn code_points_lossy(self) -> impl Iterator<Item = char> + 'a
pub fn code_points_lossy(self) -> impl Iterator<Item = char> + 'a
Gets an iterator of all the Unicode codepoints of a JsStr, replacing
unpaired surrogates with the replacement character. This is faster than
using Self::code_points.
Sourcepub fn to_std_string_with_surrogates(
&self,
) -> impl Iterator<Item = Result<String, u16>> + use<'a>
pub fn to_std_string_with_surrogates( &self, ) -> impl Iterator<Item = Result<String, u16>> + use<'a>
Decodes a JsStr into an iterator of Result<String, u16>, returning surrogates as
errors.
Sourcepub fn to_std_string(&self) -> Result<String, FromUtf16Error>
pub fn to_std_string(&self) -> Result<String, FromUtf16Error>
Decodes a JsStr into a String, returning an error if it contains any invalid data.
§Errors
FromUtf16Error if it contains any invalid data.
Sourcepub fn to_std_string_escaped(&self) -> String
pub fn to_std_string_escaped(&self) -> String
Sourcepub fn to_std_string_lossy(&self) -> String
pub fn to_std_string_lossy(&self) -> String
Sourcepub fn display_escaped(&self) -> JsStrDisplayEscaped<'a>
pub fn display_escaped(&self) -> JsStrDisplayEscaped<'a>
Gets a displayable escaped string.
This may be faster and has fewer
allocations than format!("{}", str.to_string_escaped()) when
displaying.
Sourcepub fn display_lossy(&self) -> JsStrDisplayLossy<'a>
pub fn display_lossy(&self) -> JsStrDisplayLossy<'a>
Gets a displayable lossy string.
This may be faster and has fewer
allocations than format!("{}", str.to_string_lossy()) when displaying.
Trait Implementations§
Source§impl From<JsStr<'_>> for PropertyKey
impl From<JsStr<'_>> for PropertyKey
Source§impl Ord for JsStr<'_>
impl Ord for JsStr<'_>
Source§impl PartialOrd for JsStr<'_>
impl PartialOrd for JsStr<'_>
impl<'a> Copy for JsStr<'a>
impl Eq for JsStr<'_>
impl Send for JsStr<'_>
impl Sync for JsStr<'_>
Auto Trait Implementations§
impl<'a> Freeze for JsStr<'a>
impl<'a> RefUnwindSafe for JsStr<'a>
impl<'a> Unpin for JsStr<'a>
impl<'a> UnwindSafe for JsStr<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
Source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
Source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
Source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
Source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self, then passes self.as_ref() into the pipe function.Source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self, then passes self.as_mut() into the pipe
function.Source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.Source§impl<T> Tap for T
impl<T> Tap for T
Source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read moreSource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read moreSource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read moreSource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read moreSource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.Source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.Source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in release
builds.Source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.Source§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.