#[repr(transparent)]pub struct TracedDOMString(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 will 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.)
Note: the above appears refuted by the needs of dom/encoding.
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 &str). You should assume that this conversion is
expensive. For now, you should assume that all the functions incur this
conversion cost.
Tuple Fields§
§0: RefCell<DOMStringType>Implementations§
Source§impl TracedDOMString
impl TracedDOMString
pub fn root(self) -> DOMString
Sourcefn ensure_rust_string(&self) -> RefMut<'_, String>
fn ensure_rust_string(&self) -> RefMut<'_, String>
Transforms the internal storage of this DOMString into a Rust string if it is not
yet one. This will make a copy of the underlying string data.
Sourcepub fn str(&self) -> StringView<'_>
pub fn str(&self) -> StringView<'_>
Returns the underlying rust string.
Sourcepub fn encoded_bytes<'a>(&'a self, no_gc: &'a NoGC) -> EncodedBytes<'a>
pub fn encoded_bytes<'a>(&'a self, no_gc: &'a NoGC) -> EncodedBytes<'a>
Return the EncodedBytes of this DOMString. This returns the original encoded
bytes of the string without doing any conversions.
pub fn clear(&mut self)
pub fn is_empty(&self) -> bool
Sourcepub fn len_utf8(&self) -> Utf8CodeUnits
pub fn len_utf8(&self) -> Utf8CodeUnits
The length of this string in UTF-8 code units, each one being one byte in size.
This method is the same as [DOMString::len], but the result is wrapped in a
Utf8CodeUnits to be used in code that mixes different kinds of offsets.
Note: This is different than the number of Unicode characters (or code points). A character may require multiple UTF-8 code units.
Sourcepub fn len_utf8_or_latin1(&self) -> usize
pub fn len_utf8_or_latin1(&self) -> usize
Returns a length for “is small” heuristics, whose precise definition does not matter
Sourcepub fn len_utf16(&self) -> Utf16CodeUnits
pub fn len_utf16(&self) -> Utf16CodeUnits
The length of this string in UTF-16 code units, each one being one two bytes in size.
Note: This is different than the number of Unicode characters (or code points). A character may require multiple UTF-16 code units.
Sourcepub fn make_ascii_lowercase(&mut self)
pub fn make_ascii_lowercase(&mut self)
This works the same as make_ascii_lowercase on std::string. This means that any character in [A-Z]
will be transformed to lower case but other characters stay the same (either ASCII or not ASCII).
pub fn push_str(&mut self, string_to_push: &str)
Sourcepub fn strip_leading_and_trailing_ascii_whitespace(&mut self)
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
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 ends_with_str(&self, needle: &str) -> bool
pub fn contains(&self, needle: &str) -> bool
Sourcepub fn eq_ignore_ascii_case(&self, other: &str) -> bool
pub fn eq_ignore_ascii_case(&self, other: &str) -> bool
Returns whether this DOMString is an ASCII case-insensitive match for other,
without allocating and copying temporaries.
pub fn to_ascii_lowercase(&self) -> String
fn contains_space_characters( &self, latin1_characters: &'static [u8], utf8_characters: &'static [char], ) -> bool
Sourcepub fn contains_tab_or_newline(&self) -> bool
pub fn contains_tab_or_newline(&self) -> bool
Sourcepub fn contains_html_space_characters(&self) -> bool
pub fn contains_html_space_characters(&self) -> bool
Sourcepub fn as_bytes<'a>(&'a self, no_gc: &'a NoGC) -> BytesView<'a>
pub fn as_bytes<'a>(&'a self, no_gc: &'a NoGC) -> BytesView<'a>
This returns the string in utf8 bytes, i.e., [u8] encoded with utf8.
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.
Returns true if the slice only contains bytes that are safe to use in cookie strings. https://www.ietf.org/archive/id/draft-ietf-httpbis-rfc6265bis-15.html#section-5.6-6 Not using ServoCookie::is_valid_name_or_value to prevent dependency on the net crate.
Sourcefn with_str_reference<Result>(&self, callback: fn(&str) -> Result) -> Result
fn with_str_reference<Result>(&self, callback: fn(&str) -> Result) -> Result
Sourcepub fn normalize_crlf(&self) -> String
pub fn normalize_crlf(&self) -> String
Newline replacement routine as described in step 1 of the multipart/form-data encoding algorithm and many steps of application/x-www-form-urlencoded. e.g. https://html.spec.whatwg.org/multipage/#convert-to-a-list-of-name-value-pairs
Replace every occurrence of U+000D (CR) not followed by U+000A (LF), and every occurrence of U+000A (LF) not preceded by U+000D (CR), in entry’s name, by a string consisting of a U+000D (CR) and U+000A (LF).
Trait Implementations§
Source§impl Clone for TracedDOMString
impl Clone for TracedDOMString
Source§fn clone(&self) -> TracedDOMString
fn clone(&self) -> TracedDOMString
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for TracedDOMString
impl Debug for TracedDOMString
Source§impl Default for TracedDOMString
impl Default for TracedDOMString
Source§fn default() -> TracedDOMString
fn default() -> TracedDOMString
Source§impl Display for TracedDOMString
impl Display for TracedDOMString
Source§impl Extend<char> for TracedDOMString
impl Extend<char> for TracedDOMString
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 From<String> for TracedDOMString
impl From<String> for TracedDOMString
Source§impl From<TracedDOMString> for String
impl From<TracedDOMString> for String
Source§fn from(val: TracedDOMString) -> Self
fn from(val: TracedDOMString) -> Self
Source§impl From<TracedDOMString> for Vec<u8>
impl From<TracedDOMString> for Vec<u8>
Source§fn from(value: TracedDOMString) -> Self
fn from(value: TracedDOMString) -> Self
Source§impl Hash for TracedDOMString
impl Hash for TracedDOMString
Source§impl MallocSizeOf for TracedDOMString
impl MallocSizeOf for TracedDOMString
Source§fn size_of(&self, ops: &mut MallocSizeOfOps) -> usize
fn size_of(&self, ops: &mut MallocSizeOfOps) -> usize
Source§impl Ord for TracedDOMString
impl Ord for TracedDOMString
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialEq<&str> for TracedDOMString
impl PartialEq<&str> for TracedDOMString
Source§impl PartialEq<String> for TracedDOMString
impl PartialEq<String> for TracedDOMString
Source§impl PartialEq<TracedDOMString> for String
impl PartialEq<TracedDOMString> for String
Source§fn eq(&self, other: &TracedDOMString) -> bool
fn eq(&self, other: &TracedDOMString) -> bool
self and other values to be equal, and is used by ==.Source§impl PartialEq<TracedDOMString> for str
impl PartialEq<TracedDOMString> for str
Source§fn eq(&self, other: &TracedDOMString) -> bool
fn eq(&self, other: &TracedDOMString) -> bool
self and other values to be equal, and is used by ==.Source§impl PartialEq<str> for TracedDOMString
impl PartialEq<str> for TracedDOMString
Source§impl PartialEq for TracedDOMString
impl PartialEq for TracedDOMString
Source§fn eq(&self, other: &TracedDOMString) -> bool
fn eq(&self, other: &TracedDOMString) -> bool
self and other values to be equal, and is used by ==.Source§impl PartialOrd for TracedDOMString
impl PartialOrd for TracedDOMString
Source§impl Traceable for TracedDOMString
impl Traceable for TracedDOMString
Source§impl Zeroize for TracedDOMString
impl Zeroize for TracedDOMString
impl Eq for TracedDOMString
Auto Trait Implementations§
impl !Freeze for TracedDOMString
impl !RefUnwindSafe for TracedDOMString
impl !Send for TracedDOMString
impl !Sync for TracedDOMString
impl Unpin for TracedDOMString
impl UnsafeUnpin for TracedDOMString
impl UnwindSafe for TracedDOMString
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> 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