pub struct JsString {/* private fields */ }Expand description
A Latin1 or UTF-16–encoded, reference counted, immutable string.
This is pretty similar to aRc<[u16]>, but without thelength metadata associated with theRc fat pointer. Instead, the length of every string isstored on the heap, along with its reference counter and its data.
The string can be latin1 (stored as a byte for space efficiency) or U16 encoding.
We define some commonly used string constants in an interner. For these strings, we don’t allocatememory on the heap to reduce the overhead of memory allocation and reference counting.
Implementations§
Source§implJsString
implJsString
Sourcepub fnwindows(&self, size:usize) -> Windows<'_>
pub fnwindows(&self, size:usize) -> Windows<'_>
Create an iterator over overlapping subslices of length size.
Sourcepub fnto_std_string_escaped(&self) ->String
pub fnto_std_string_escaped(&self) ->String
Sourcepub fnto_std_string_lossy(&self) ->String
pub fnto_std_string_lossy(&self) ->String
Sourcepub fnto_std_string(&self) ->Result<String,FromUtf16Error>
pub fnto_std_string(&self) ->Result<String,FromUtf16Error>
Decodes aJsString into aString, returning an error if the string contains unpairedsurrogates.
§Errors
FromUtf16Error if it contains any invalid data.
Sourcepub fnto_std_string_with_surrogates( &self,) -> implIterator<Item =Result<String,u16>>
pub fnto_std_string_with_surrogates( &self,) -> implIterator<Item =Result<String,u16>>
Decodes aJsString into an iterator ofResult<String, u16>, returning surrogates aserrors.
Sourcepub fnmap_valid_segments<F>(&self, f: F) ->JsString
pub fnmap_valid_segments<F>(&self, f: F) ->JsString
Maps the valid segments of an UTF16 string and leaves the unpaired surrogates unchanged.
Sourcepub fncode_points(&self) -> implIterator<Item =CodePoint> +Clone
pub fncode_points(&self) -> implIterator<Item =CodePoint> +Clone
Gets an iterator of all the Unicode codepoints of aJsString.
Sourcepub fnindex_of( &self, search_value:JsStr<'_>, from_index:usize,) ->Option<usize>
pub fnindex_of( &self, search_value:JsStr<'_>, from_index:usize,) ->Option<usize>
Sourcepub fncode_point_at(&self, position:usize) ->CodePoint
pub fncode_point_at(&self, position:usize) ->CodePoint
Abstract operationCodePointAt( string, position ).
The abstract operationCodePointAt takes argumentsstring (a String) andposition (anon-negative integer) and returns a Record with fields[[CodePoint]] (a code point),[[CodeUnitCount]] (a positive integer), and[[IsUnpairedSurrogate]] (a Boolean). Itinterprets string as a sequence of UTF-16 encoded code points, as described in 6.1.4, and readsfrom it a single code point starting with the code unit at indexposition.
More information:
§Panics
Ifposition is smaller than size of string.
Sourcepub fntrim_start(&self) ->JsStr<'_>
pub fntrim_start(&self) ->JsStr<'_>
Trim whitespace from the start of theJsString.
Sourcepub fnget<'a, I>(&'a self, index: I) ->Option<<I as JsSliceIndex<'a>>::Value>where I: JsSliceIndex<'a>,
pub fnget<'a, I>(&'a self, index: I) ->Option<<I as JsSliceIndex<'a>>::Value>where I: JsSliceIndex<'a>,
Get the element a the given index,None otherwise.
Sourcepub unsafe fnget_unchecked<'a, I>( &'a self, index: I,) -> <I as JsSliceIndex<'a>>::Valuewhere I: JsSliceIndex<'a>,
pub unsafe fnget_unchecked<'a, I>( &'a 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 fnget_expect<'a, I>(&'a self, index: I) -> <I as JsSliceIndex<'a>>::Valuewhere I: JsSliceIndex<'a>,
pub fnget_expect<'a, I>(&'a self, index: I) -> <I as JsSliceIndex<'a>>::Valuewhere I: JsSliceIndex<'a>,
Sourcepub fndisplay_escaped(&self) -> JsStrDisplayEscaped<'_>
pub fndisplay_escaped(&self) -> JsStrDisplayEscaped<'_>
Gets a displayable escaped string. This may be faster and has fewerallocations thanformat!("{}", str.to_string_escaped()) whendisplaying.
Sourcepub fndisplay_lossy(&self) -> JsStrDisplayLossy<'_>
pub fndisplay_lossy(&self) -> JsStrDisplayLossy<'_>
Gets a displayable lossy string. This may be faster and has fewerallocations thanformat!("{}", str.to_string_lossy()) when displaying.
Sourcepub fninto_raw(self) ->NonNull<RawJsString>
pub fninto_raw(self) ->NonNull<RawJsString>
Consumes theJsString, returning a pointer toRawJsString.
To avoid a memory leak the pointer must be converted back to aJsString usingJsString::from_raw.
Sourcepub unsafe fnfrom_raw(ptr:NonNull<RawJsString>) ->JsString
pub unsafe fnfrom_raw(ptr:NonNull<RawJsString>) ->JsString
Constructs aJsString from a pointer toRawJsString.
The raw pointer must have been previously returned by a call toJsString::into_raw.
§Safety
This function is unsafe because improper use may lead to memory unsafety,even if the returnedJsString is never accessed.
Source§implJsString
implJsString
Sourcepub const fnfrom_static_js_str(src: &'staticJsStr<'static>) ->JsString
pub const fnfrom_static_js_str(src: &'staticJsStr<'static>) ->JsString
Create aJsString from a static js string.
Sourcepub fnconcat(x:JsStr<'_>, y:JsStr<'_>) ->JsString
pub fnconcat(x:JsStr<'_>, y:JsStr<'_>) ->JsString
Creates a newJsString from the concatenation ofx andy.
Sourcepub fnconcat_array(strings: &[JsStr<'_>]) ->JsString
pub fnconcat_array(strings: &[JsStr<'_>]) ->JsString
Creates a newJsString from the concatenation of every element ofstrings.
Trait Implementations§
Source§implFrom<JsString> forFunctionBinding
implFrom<JsString> forFunctionBinding
Source§implFrom<JsString> forPropertyKey
implFrom<JsString> forPropertyKey
Source§impl<'a>IntoIterator for &'aJsString
impl<'a>IntoIterator for &'aJsString
Source§implOrd forJsString
implOrd forJsString
Source§implPartialOrd forJsString
implPartialOrd forJsString
Source§implTrace forJsString
implTrace forJsString
Source§unsafe fntrace_non_roots(&self)
unsafe fntrace_non_roots(&self)
Source§fnrun_finalizer(&self)
fnrun_finalizer(&self)
Finalize::finalize on this object and allcontained subobjects.implEq forJsString
implJsData forJsString
Auto Trait Implementations§
implFreeze forJsString
impl !RefUnwindSafe forJsString
impl !Send forJsString
impl !Sync forJsString
implUnpin forJsString
impl !UnwindSafe forJsString
Blanket Implementations§
Source§impl<T>BorrowMut<T> for Twhere T: ?Sized,
impl<T>BorrowMut<T> for Twhere T: ?Sized,
Source§fnborrow_mut(&mut self) ->&mut T
fnborrow_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§fnequivalent(&self, key:&K) ->bool
fnequivalent(&self, key:&K) ->bool
key and returntrue 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§fninto_either(self, into_left:bool) ->Either<Self, Self>
fninto_either(self, into_left:bool) ->Either<Self, Self>
self into aLeft variant ofEither<Self, Self>ifinto_left istrue.Convertsself into aRight variant ofEither<Self, Self>otherwise.Read moreSource§fninto_either_with<F>(self, into_left: F) ->Either<Self, Self>
fninto_either_with<F>(self, into_left: F) ->Either<Self, Self>
self into aLeft variant ofEither<Self, Self>ifinto_left(&self) returnstrue.Convertsself into aRight variant ofEither<Self, Self>otherwise.Read moreSource§impl<T>NativeObject for T
impl<T>NativeObject for T
Source§fnas_any(&self) -> &(dynAny + 'static)
fnas_any(&self) -> &(dynAny + 'static)
NativeObject to a&dyn Any.Source§fnas_mut_any(&mut self) -> &mut (dynAny + 'static)
fnas_mut_any(&mut self) -> &mut (dynAny + 'static)
NativeObject to a&mut dyn Any.Source§fntype_name_of_value(&self) -> &'staticstr
fntype_name_of_value(&self) -> &'staticstr
Source§impl<T>Pipe for Twhere T: ?Sized,
impl<T>Pipe for Twhere T: ?Sized,
Source§fnpipe<R>(self, func: implFnOnce(Self) -> R) -> Rwhere Self:Sized,
fnpipe<R>(self, func: implFnOnce(Self) -> R) -> Rwhere Self:Sized,
Source§fnpipe_ref<'a, R>(&'a self, func: implFnOnce(&'a Self) -> R) -> Rwhere R: 'a,
fnpipe_ref<'a, R>(&'a self, func: implFnOnce(&'a Self) -> R) -> Rwhere R: 'a,
self and passes that borrow into the pipe function.Read moreSource§fnpipe_ref_mut<'a, R>(&'a mut self, func: implFnOnce(&'a mut Self) -> R) -> Rwhere R: 'a,
fnpipe_ref_mut<'a, R>(&'a mut self, func: implFnOnce(&'a mut Self) -> R) -> Rwhere R: 'a,
self and passes that borrow into the pipe function.Read moreSource§fnpipe_borrow<'a, B, R>(&'a self, func: implFnOnce(&'a B) -> R) -> R
fnpipe_borrow<'a, B, R>(&'a self, func: implFnOnce(&'a B) -> R) -> R
Source§fnpipe_borrow_mut<'a, B, R>( &'a mut self, func: implFnOnce(&'a mut B) -> R,) -> R
fnpipe_borrow_mut<'a, B, R>( &'a mut self, func: implFnOnce(&'a mut B) -> R,) -> R
Source§fnpipe_as_ref<'a, U, R>(&'a self, func: implFnOnce(&'a U) -> R) -> R
fnpipe_as_ref<'a, U, R>(&'a self, func: implFnOnce(&'a U) -> R) -> R
self, then passesself.as_ref() into the pipe function.Source§fnpipe_as_mut<'a, U, R>(&'a mut self, func: implFnOnce(&'a mut U) -> R) -> R
fnpipe_as_mut<'a, U, R>(&'a mut self, func: implFnOnce(&'a mut U) -> R) -> R
self, then passesself.as_mut() into the pipefunction.Source§fnpipe_deref<'a, T, R>(&'a self, func: implFnOnce(&'a T) -> R) -> R
fnpipe_deref<'a, T, R>(&'a self, func: implFnOnce(&'a T) -> R) -> R
self, then passesself.deref() into the pipe function.Source§impl<T>Tap for T
impl<T>Tap for T
Source§fntap_borrow<B>(self, func: implFnOnce(&B)) -> Self
fntap_borrow<B>(self, func: implFnOnce(&B)) -> Self
Borrow<B> of a value.Read moreSource§fntap_borrow_mut<B>(self, func: implFnOnce(&mut B)) -> Self
fntap_borrow_mut<B>(self, func: implFnOnce(&mut B)) -> Self
BorrowMut<B> of a value.Read moreSource§fntap_ref<R>(self, func: implFnOnce(&R)) -> Self
fntap_ref<R>(self, func: implFnOnce(&R)) -> Self
AsRef<R> view of a value.Read moreSource§fntap_ref_mut<R>(self, func: implFnOnce(&mut R)) -> Self
fntap_ref_mut<R>(self, func: implFnOnce(&mut R)) -> Self
AsMut<R> view of a value.Read moreSource§fntap_deref<T>(self, func: implFnOnce(&T)) -> Self
fntap_deref<T>(self, func: implFnOnce(&T)) -> Self
Deref::Target of a value.Read moreSource§fntap_deref_mut<T>(self, func: implFnOnce(&mut T)) -> Self
fntap_deref_mut<T>(self, func: implFnOnce(&mut T)) -> Self
Deref::Target of a value.Read moreSource§fntap_dbg(self, func: implFnOnce(&Self)) -> Self
fntap_dbg(self, func: implFnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.Source§fntap_mut_dbg(self, func: implFnOnce(&mut Self)) -> Self
fntap_mut_dbg(self, func: implFnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in releasebuilds.Source§fntap_borrow_dbg<B>(self, func: implFnOnce(&B)) -> Self
fntap_borrow_dbg<B>(self, func: implFnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in releasebuilds.Source§fntap_borrow_mut_dbg<B>(self, func: implFnOnce(&mut B)) -> Self
fntap_borrow_mut_dbg<B>(self, func: implFnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in releasebuilds.Source§fntap_ref_dbg<R>(self, func: implFnOnce(&R)) -> Self
fntap_ref_dbg<R>(self, func: implFnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in releasebuilds.Source§fntap_ref_mut_dbg<R>(self, func: implFnOnce(&mut R)) -> Self
fntap_ref_mut_dbg<R>(self, func: implFnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in releasebuilds.Source§fntap_deref_dbg<T>(self, func: implFnOnce(&T)) -> Self
fntap_deref_dbg<T>(self, func: implFnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in releasebuilds.