Skip to content

web-sys function bindings should be generic over AsRef<T> instead of &T #977

Closed
@bgourlie

Description

@bgourlie

Take the definition of append_child for example.

pub fn append_child(&self, node: &Node) -> Result<Node, JsValue>

I find myself having to manually coerce an Element into the correct type, for example:

let document = web_sys::window().unwrap().document().unwrap();
let val = document.create_element("p").unwrap();
val.set_inner_html("Hello from Rust, WebAssembly, WebPack, and web-sys!");
AsRef::<Node>::as_ref(&document.body().unwrap()).append_child(AsRef::<Node>::as_ref(&val));

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions