Skip to main content

DOMString

Struct DOMString 

Source
pub struct DOMString(RootedTraceableBox<TracedDOMString>);

Tuple Fields§

§0: RootedTraceableBox<TracedDOMString>

Implementations§

Source§

impl DOMString

Source

pub fn new() -> DOMString

Creates a new DOMString.

Source

pub fn from_js_string( cx: &mut JSContext, 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. https://webidl.spec.whatwg.org/#js-DOMString

Source

pub unsafe fn from_raw_js_string( cx: &JSContext, string_ptr: *mut JSString, ) -> Result<DOMString, DOMStringErrorType>

Takes a raw *mut JSString and creates a DOMString out of it. Prefer DOMString::from_js_string if you have a HandleValue. Seee DOMString::from_js_string for more detail.

§Safety

*mut JSString needs to point to a valid JSString.

Source

pub fn from_static(s: &'static str) -> DOMString

Creates a DOMString from a &'static str reference. More efficient than allocating the string.

Source

pub fn traced(self) -> TracedDOMString

Source

pub fn str(&self) -> StringView<'_>

Methods from Deref<Target = TracedDOMString>§

Source

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.

Source

fn debug_js(&self, cx: &JSContext)

Debug the current state of the string without modifying it.

Source

pub fn str(&self) -> StringView<'_>

Returns the underlying rust string.

Source

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.

Source

pub fn clear(&mut self)

Source

pub fn is_empty(&self) -> bool

Source

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.

Source

pub fn len_utf8_or_latin1(&self) -> usize

Returns a length for “is small” heuristics, whose precise definition does not matter

Source

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.

Source

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).

Source

pub fn push_str(&mut self, string_to_push: &str)

Source

pub fn strip_leading_and_trailing_ascii_whitespace(&mut self)

Source

pub fn is_valid_floating_point_number_string(&self) -> bool

Source

pub fn parse<T: FromStr>(&self) -> Result<T, <T as FromStr>::Err>

Source

pub fn parse_floating_point_number(&self) -> Option<f64>

Source

pub fn set_best_representation_of_the_floating_point_number(&mut self)

Source

pub fn to_lowercase(&self) -> String

Source

pub fn to_uppercase(&self) -> String

Source

pub fn strip_newlines(&mut self)

Source

pub fn normalize_newlines(&mut self)

Normalize newlines according to https://infra.spec.whatwg.org/#normalize-newlines.

Source

pub fn starts_with(&self, c: char) -> bool

Pattern is not yet stable in rust, hence, we need different methods for str and char

Source

pub fn starts_with_str(&self, needle: &str) -> bool

Source

pub fn ends_with_str(&self, needle: &str) -> bool

Source

pub fn contains(&self, needle: &str) -> bool

Source

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.

https://infra.spec.whatwg.org/#ascii-case-insensitive

Source

pub fn to_ascii_lowercase(&self) -> String

Source

fn contains_space_characters( &self, latin1_characters: &'static [u8], utf8_characters: &'static [char], ) -> bool

Source

pub fn contains_tab_or_newline(&self) -> bool

Source

pub fn contains_html_space_characters(&self) -> bool

Source

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.

Source

pub fn is_ascii_lowercase(&self) -> bool

Tests if there are only ascii lowercase characters. Does not include special characters.

Source

pub fn is_ascii(&self) -> bool

Is the string only ascii 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.

Source

fn with_str_reference<Result>(&self, callback: fn(&str) -> Result) -> Result

Call the callback with a &str reference of the string stored in this DOMString. Note that if the DOMString cannot be interpreted as a Rust string a conversion will be done.

Source

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 DOMString

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for DOMString

Source§

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

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

impl Default for DOMString

Source§

fn default() -> DOMString

Returns the “default value” for a type. Read more
Source§

impl Deref for DOMString

Source§

type Target = TracedDOMString

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl DerefMut for DOMString

Source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.
Source§

impl Display for DOMString

Source§

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

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

impl Eq for DOMString

Source§

impl From<&DOMString> for LocalName

Source§

fn from(dom_string: &DOMString) -> LocalName

Converts to this type from the input type.
Source§

impl From<&str> for DOMString

If you have a static str use the provided DOMString::from_static.

Source§

fn from(string: &str) -> Self

Converts to this type from the input type.
Source§

impl From<Cow<'_, str>> for DOMString

Source§

fn from(value: Cow<'_, str>) -> Self

Converts to this type from the input type.
Source§

impl From<DOMString> for LocalName

Source§

fn from(dom_string: DOMString) -> LocalName

Converts to this type from the input type.
Source§

impl From<DOMString> for Namespace

Source§

fn from(dom_string: DOMString) -> Namespace

Converts to this type from the input type.
Source§

impl From<DOMString> for Atom

Source§

fn from(dom_string: DOMString) -> Atom

Converts to this type from the input type.
Source§

impl From<DOMString> for String

Source§

fn from(value: DOMString) -> Self

Converts to this type from the input type.
Source§

impl From<DOMString> for Vec<u8>

Source§

fn from(value: DOMString) -> Self

Converts to this type from the input type.
Source§

impl From<String> for DOMString

Source§

fn from(string: String) -> Self

Converts to this type from the input type.
Source§

impl From<USVString> for DOMString

Source§

fn from(value: USVString) -> Self

Converts to this type from the input type.
Source§

impl FromJSValConvertible for DOMString

Source§

type Config = StringificationBehavior

Optional configurable behaviour switch; use () for no configuration.
Source§

fn from_jsval( cx: &mut JSContext, value: HandleValue<'_>, null_behavior: StringificationBehavior, ) -> Result<ConversionResult<DOMString>, ()>

Convert 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 Hash for DOMString

Source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl MallocSizeOf for DOMString

Source§

fn size_of(&self, ops: &mut MallocSizeOfOps) -> usize

Measure the heap usage of all descendant heap-allocated structures, but not the space taken up by the value itself.
Source§

impl PartialEq for DOMString

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl PartialEq<&str> for DOMString

Source§

fn eq(&self, other: &&str) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl PartialEq<DOMString> for String

Source§

fn eq(&self, other: &DOMString) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl PartialEq<DOMString> for str

Source§

fn eq(&self, other: &DOMString) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl PartialEq<String> for DOMString

Source§

fn eq(&self, other: &String) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl PartialEq<str> for DOMString

Source§

fn eq(&self, other: &str) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl PartialOrd for DOMString

Source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 (const: unstable) · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 (const: unstable) · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 (const: unstable) · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl RecordKey for DOMString

Source§

fn to_utf16_vec(&self) -> Vec<u16>

Source§

fn from_id( cx: &mut JSContext, id: HandleId<'_>, ) -> Result<ConversionResult<Self>, ()>

Attempt to extract a key from a JS id.
Source§

impl ToJSValConvertible for DOMString

Source§

fn to_jsval(&self, cx: &mut JSContext, rval: MutableHandleValue<'_>)

Convert self to a JSVal. JSAPI failure causes a panic.
Source§

impl Traceable for DOMString

Source§

unsafe fn trace(&self, tracer: *mut JSTracer)

Trace self.
Source§

impl Zeroize for DOMString

Source§

fn zeroize(&mut self)

Zero out this object from memory using Rust intrinsics which ensure the zeroization operation is not “optimized away” by the compiler.

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> Downcast<T> for T

Source§

fn downcast(&self) -> &T

Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> MaybeBoxed<Box<T>> for T

Source§

fn maybe_boxed(self) -> Box<T>

Convert
Source§

impl<T> MaybeBoxed<T> for T

Source§

fn maybe_boxed(self) -> T

Convert
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, S> SimdFrom<T, S> for T
where S: Simd,

Source§

fn simd_from(_simd: S, value: T) -> T

Source§

impl<F, T, S> SimdInto<T, S> for F
where T: SimdFrom<F, S>, S: Simd,

Source§

fn simd_into(self, simd: S) -> T

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.
Source§

impl<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more