#[repr(transparent)]pub struct DOMString(RefCell<DOMStringType>);Expand description
This type corresponds to the DOMString type in WebIDL.
Conceptually, a DOMString has the same value space as a JavaScript String, i.e., an array of 16-bit code units representing UTF-16, potentially with unpaired surrogates present (also sometimes called WTF-16).
However, Rust Strings are guaranteed to be valid UTF-8, and as such have
a smaller value space than WTF-16 (i.e., some JavaScript String values
can not be represented as a Rust String). This introduces the question of
what to do with values being passed from JavaScript to Rust that contain
unpaired surrogates.
The hypothesis is that it does not matter much how exactly those values are transformed, because passing unpaired surrogates into the DOM is very rare. Instead Servo withh replace the unpaired surrogate by a U+FFFD replacement character.
Currently, the lack of crash reports about this issue provides some
evidence to support the hypothesis. This evidence will hopefully be used to
convince other browser vendors that it would be safe to replace unpaired
surrogates at the boundary between JavaScript and native code. (This would
unify the DOMString and USVString types, both in the WebIDL standard
and in Servo.)
This string class will keep either the Reference to the mozjs object alive
or will have an internal rust string.
We currently default to doing most of the string operation on the rust side.
You should use str() to get the Rust string (represented by a StringView
which you can deref to a string). You should assume that this conversion costs.
You should assume that all the functions incur the conversion cost.
Tuple Fields§
§0: RefCell<DOMStringType>Implementations§
Source§impl DOMString
impl DOMString
Sourcepub fn from_js_string(
cx: SafeJSContext,
value: HandleValue<'_>,
) -> Result<DOMString, DOMStringErrorType>
pub fn from_js_string( cx: SafeJSContext, value: HandleValue<'_>, ) -> Result<DOMString, DOMStringErrorType>
Creates the string from js. If the string can be encoded in latin1, just take the reference to the JSString. Otherwise do the conversion to utf8 now.
pub fn from_string(s: String) -> DOMString
Sourcepub fn str(&self) -> StringView<'_>
pub fn str(&self) -> StringView<'_>
Returns the underlying rust string.
Sourcepub fn view(&self) -> EncodedBytesView<'_>
pub fn view(&self) -> EncodedBytesView<'_>
Use this if you want to work on the EncodedBytes directly.
This will not do any conversions for you.
pub fn clear(&mut self)
pub fn is_empty(&self) -> bool
Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
This length (as rust spec) is in bytes if the string would be utf8 not chars.
pub fn make_ascii_lowercase(&mut self)
pub fn push_str(&mut self, s: &str)
pub fn strip_leading_and_trailing_ascii_whitespace(&mut self)
Sourcepub fn is_valid_floating_point_number_string(&self) -> bool
pub fn is_valid_floating_point_number_string(&self) -> bool
This is a dom spec
pub fn parse<T: FromStr>(&self) -> Result<T, <T as FromStr>::Err>
Sourcepub fn parse_floating_point_number(&self) -> Option<f64>
pub fn parse_floating_point_number(&self) -> Option<f64>
Sourcepub fn set_best_representation_of_the_floating_point_number(&mut self)
pub fn set_best_representation_of_the_floating_point_number(&mut self)
pub fn to_lowercase(&self) -> String
pub fn to_uppercase(&self) -> String
pub fn strip_newlines(&mut self)
Sourcepub fn normalize_newlines(&mut self)
pub fn normalize_newlines(&mut self)
Normalize newlines according to https://infra.spec.whatwg.org/#normalize-newlines.
pub fn replace(self, needle: &str, replace_char: &str) -> DOMString
Sourcepub fn starts_with(&self, c: char) -> bool
pub fn starts_with(&self, c: char) -> bool
Pattern is not yet stable in rust, hence, we need different methods for str and char
pub fn starts_with_str(&self, needle: &str) -> bool
pub fn contains(&self, needle: &str) -> bool
pub fn to_ascii_lowercase(&self) -> String
pub fn contains_html_space_characters(&self) -> bool
Sourcepub fn is_ascii_lowercase(&self) -> bool
pub fn is_ascii_lowercase(&self) -> bool
Tests if there are only ascii lowercase characters. Does not include special characters.
Trait Implementations§
Source§impl Extend<char> for DOMString
impl Extend<char> for DOMString
Source§fn extend<T: IntoIterator<Item = char>>(&mut self, iter: T)
fn extend<T: IntoIterator<Item = char>>(&mut self, iter: T)
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one)Source§impl FromJSValConvertible for DOMString
impl FromJSValConvertible for DOMString
Source§type Config = StringificationBehavior
type Config = StringificationBehavior
Source§unsafe fn from_jsval(
cx: *mut JSContext,
value: HandleValue<'_>,
null_behavior: StringificationBehavior,
) -> Result<ConversionResult<DOMString>, ()>
unsafe fn from_jsval( cx: *mut JSContext, value: HandleValue<'_>, null_behavior: StringificationBehavior, ) -> Result<ConversionResult<DOMString>, ()>
val to type Self.
Optional configuration of type T can be passed as the option
argument.
If it returns Err(()), a JSAPI exception is pending.
If it returns Ok(Failure(reason)), there is no pending JSAPI exception.Source§impl MallocSizeOf for DOMString
impl MallocSizeOf for DOMString
Source§fn size_of(&self, ops: &mut MallocSizeOfOps) -> usize
fn size_of(&self, ops: &mut MallocSizeOfOps) -> usize
Source§impl Ord for DOMString
impl Ord for DOMString
Source§impl PartialOrd for DOMString
impl PartialOrd for DOMString
Source§impl ToJSValConvertible for DOMString
impl ToJSValConvertible for DOMString
impl Eq for DOMString
Auto Trait Implementations§
impl !Freeze for DOMString
impl !RefUnwindSafe for DOMString
impl !Send for DOMString
impl !Sync for DOMString
impl Unpin for DOMString
impl !UnwindSafe for DOMString
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<T> Filterable for T
impl<T> Filterable for T
Source§fn filterable(
self,
filter_name: &'static str,
) -> RequestFilterDataProvider<T, fn(DataRequest<'_>) -> bool>
fn filterable( self, filter_name: &'static str, ) -> RequestFilterDataProvider<T, fn(DataRequest<'_>) -> bool>
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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 more