pub struct WElement(/* private fields */);wasm only.Expand description
An HTML element, usable from JavaScript.
The builder methods consume and return the handle so they chain in JS exactly as they do in Rust:
const card = element("div").addClass("card").child(element("h1").text("Hi"));
card.render(); // '<div class="card"><h1>Hi</h1></div>'Implementations§
Source§impl WElement
impl WElement
Sourcepub fn attr(self, key: &str, value: &str) -> Self
pub fn attr(self, key: &str, value: &str) -> Self
Appends an attribute, escaping the value.
URL attributes go through the same policy as Element::attr: a script URL renders
as #.
Sourcepub fn trusted_url(self, key: &str, value: &str) -> Self
pub fn trusted_url(self, key: &str, value: &str) -> Self
Replaces key with a URL written as given, even if it is a script URL.
The value is still attribute-escaped. Use this only for a URL the page author wrote.
Sourcepub fn bool_attr(self, key: &str) -> Self
pub fn bool_attr(self, key: &str) -> Self
Appends a boolean attribute, which renders as a bare key.
Sourcepub fn child(self, child: WElement) -> Self
pub fn child(self, child: WElement) -> Self
Appends a child element. The child handle is consumed.
Sourcepub fn add_classes(self, classes: Vec<String>) -> Self
pub fn add_classes(self, classes: Vec<String>) -> Self
Appends several class names.
Sourcepub fn raw_child(self, markup: &str) -> Self
pub fn raw_child(self, markup: &str) -> Self
Appends markup without escaping it, as a child.
The element-level counterpart of rawText; like it, never pass user data.
Sourcepub fn self_closing(self, yes: bool) -> Self
pub fn self_closing(self, yes: bool) -> Self
Renders this element as <tag … /> (or <tag … > in HTML mode) with no content,
even when the tag is not a void element.
Sourcepub fn render_pretty(&self) -> String
pub fn render_pretty(&self) -> String
Renders with indentation.
Sourcepub fn render_with_options(
&self,
pretty: bool,
indent: &str,
xhtml: bool,
) -> String
pub fn render_with_options( &self, pretty: bool, indent: &str, xhtml: bool, ) -> String
Renders with explicit options: pretty turns indentation on, indent is the string
written per level, and xhtml closes void elements as <br />.
Sourcepub fn render_bytes(&self) -> Vec<u8> ⓘ
pub fn render_bytes(&self) -> Vec<u8> ⓘ
Renders on a single line, as UTF-8 bytes, which spares Node a UTF-16 round trip.
Trait Implementations§
Source§impl FromWasmAbi for WElement
impl FromWasmAbi for WElement
Source§impl IntoWasmAbi for WElement
impl IntoWasmAbi for WElement
Source§impl LongRefFromWasmAbi for WElement
impl LongRefFromWasmAbi for WElement
Source§impl OptionFromWasmAbi for WElement
impl OptionFromWasmAbi for WElement
Source§impl OptionIntoWasmAbi for WElement
impl OptionIntoWasmAbi for WElement
Source§impl RefFromWasmAbi for WElement
impl RefFromWasmAbi for WElement
Source§type Abi = WasmPtr<WasmRefCell<WElement>>
type Abi = WasmPtr<WasmRefCell<WElement>>
Self are recovered from.Source§impl RefMutFromWasmAbi for WElement
impl RefMutFromWasmAbi for WElement
impl SupportsConstructor for WElement
impl SupportsInstanceProperty for WElement
impl SupportsStaticProperty for WElement
Source§impl TryFromJsValue for WElement
impl TryFromJsValue for WElement
Source§impl VectorFromWasmAbi for WElement
impl VectorFromWasmAbi for WElement
Source§impl VectorIntoWasmAbi for WElement
impl VectorIntoWasmAbi for WElement
Auto Trait Implementations§
impl Freeze for WElement
impl RefUnwindSafe for WElement
impl Send for WElement
impl Sync for WElement
impl Unpin for WElement
impl UnsafeUnpin for WElement
impl UnwindSafe for WElement
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<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> Pointable for T
impl<T> Pointable for T
Source§impl<T> ReturnWasmAbi for Twhere
T: IntoWasmAbi,
impl<T> ReturnWasmAbi for Twhere
T: IntoWasmAbi,
Source§type Abi = <T as IntoWasmAbi>::Abi
type Abi = <T as IntoWasmAbi>::Abi
IntoWasmAbi::AbiSource§fn return_abi(self) -> <T as ReturnWasmAbi>::Abi
fn return_abi(self) -> <T as ReturnWasmAbi>::Abi
IntoWasmAbi::into_abi, except that it may throw and never
return in the case of Err.