pub trait HoldsElement {
// Required method
fn element(&self) -> ElementWrapper<'_>;
}Expand description
If a struct holds onto an element it can automatically implement DomQuery. ElementWrapper is just the wrapper around web_sys::Element So this could be implemented as follows
pub struct ServerFrontEndStruct{
elem:web_sys::Element,
}
impl ServerFrontEndStruct{
fn new() -> Self {
let document = web_sys::window().unwrap().document().unwrap();
Self{elem:document.body().unwrap().unchecked_into::<HtmlElement>()}
}
}
impl HoldsElement for ServerFrontEndStruct{
fn element(&self) -> ElementWrapper{
ElementWrapper(&self.document)
}
}And now you can use DomQuery on ServerFrontEndStruct.