Skip to main content

SpecialAttributes

Struct SpecialAttributes 

Source
pub struct SpecialAttributes<Dom: RealDom> {
    pub dangerous_inner_html: Option<String>,
    /* private fields */
}
Expand description

A specially supported attributes.

Fields§

§dangerous_inner_html: Option<String>

Allows setting the innerHTML of an element.

§Danger

Be sure to escape all untrusted input to avoid cross site scripting attacks.

Implementations§

Source§

impl<Dom: RealDom> SpecialAttributes<Dom>

Source

pub fn key(&self) -> Option<&str>

Keys can distinguish two elements that have the same tag.

For example, if one div has key old-key, and another div has key new-key, the two elements are considered different.

Source

pub fn set_key<Key>(&mut self, key: Key)
where Key: Into<Cow<'static, str>>,

Set the element’s key.

Source

pub fn on_create_element_key(&self) -> Option<&Cow<'static, str>>

Returns the element’s key if an on_create_element function is set.

Source

pub fn set_key_and_on_create_element<Key, Func>(&mut self, key: Key, func: Func)
where Key: Into<Cow<'static, str>>, Func: FnMut(Dom::Element) + 'static,

Source

pub fn set_on_create_element<Func>( &mut self, func: Func, ) -> Result<(), KeyNotSetError>
where Func: FnMut(Dom::Element) + 'static,

Set the [SpecialAttributes.on_create_element] function.

§Key

The SpecialAttributes::key is used when one virtual-node is being patched over another.

If the new node’s key is different from the old node’s key, the on create element function gets called.

If the keys are the same, the function does not get called.

§Examples
use wasm_bindgen::JsValue;

let mut node = VirtualNodeWebSys::new_element("div");

// A key can be any `Into<Cow<'static, str>>`.
let key = "some-key";

let on_create_elem = move |elem: web_sys::Element| {
    assert_eq!(elem.id(), "");
};

let elem = node.as_elem_mut().unwrap();
elem.special_attributes.set_key(key);
elem.special_attributes.set_on_create_element(on_create_elem).unwrap();
Source

pub fn maybe_call_on_create_element(&self, element: &Dom::Element)

If an on_create_element function was set, call it.

Source§

impl<Dom: RealDom> SpecialAttributes<Dom>

Source

pub fn on_remove_element_key(&self) -> Option<&Cow<'static, str>>

Returns the element’s key if an on_remove_element function is set.

Source

pub fn set_on_remove_element<Func>( &mut self, func: Func, ) -> Result<(), KeyNotSetError>
where Func: FnMut(Dom::Element) + 'static,

Set the [SpecialAttributes.on_remove_element] function.

§Key

The key is used when one virtual-node is being patched over another.

If the old node’s key is different from the new node’s key, the on remove element function gets called for the old element.

If the keys are the same, the function does not get called.

§Examples
use wasm_bindgen::JsValue;

let mut node = VirtualNodeWebSys::new_element("div");

// A key can be any `Into<Cow<'static, str>>`.
let key = "some-key";

let on_remove_elem = move |elem: web_sys::Element| {
    assert_eq!(elem.id(), "");
};

let elem = node.as_elem_mut().unwrap();
elem.special_attributes.set_key(key);
elem.special_attributes.set_on_remove_element(on_remove_elem);
Source

pub fn maybe_call_on_remove_element(&self, element: &Dom::Element)

If an on_remove_element function was set, call it.

Trait Implementations§

Source§

impl<Dom: RealDom> Default for SpecialAttributes<Dom>

Source§

fn default() -> Self

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

impl<Dom: RealDom> PartialEq for SpecialAttributes<Dom>

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

Auto Trait Implementations§

§

impl<Dom> !Freeze for SpecialAttributes<Dom>

§

impl<Dom> !RefUnwindSafe for SpecialAttributes<Dom>

§

impl<Dom> !Send for SpecialAttributes<Dom>

§

impl<Dom> !Sync for SpecialAttributes<Dom>

§

impl<Dom> !UnwindSafe for SpecialAttributes<Dom>

§

impl<Dom> Unpin for SpecialAttributes<Dom>
where Option<CreateOrRemoveElementFn<Dom>>: Unpin,

§

impl<Dom> UnsafeUnpin for SpecialAttributes<Dom>
where Option<CreateOrRemoveElementFn<Dom>>: UnsafeUnpin,

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<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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, 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<S, T> Upcast<T> for S
where T: UpcastFrom<S> + ?Sized, S: ?Sized,

Source§

fn upcast(&self) -> &T
where Self: ErasableGeneric, T: Sized + ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider ref type within the Wasm bindgen generics type system. Read more
Source§

fn upcast_into(self) -> T
where Self: Sized + ErasableGeneric, T: Sized + ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider type within the Wasm bindgen generics type system. Read more