Skip to content

Commit 2560356

Browse files
author
mc1098
committed
Remove Deref of wrapped type in custom_event macro
Implementing Deref automatically prevents users from providing a more strongly typed alternatives. This will be common when wrapping `web_sys::CustomEvent`, as a user could provide a `detail` method on the event which returns a specific type and not just a JsValue.
1 parent 5bcb652 commit 2560356

File tree

2 files changed

+2
-11
lines changed

2 files changed

+2
-11
lines changed

packages/yew-macro/src/custom_event.rs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -76,23 +76,15 @@ pub fn custom_event_impl(name: CustomEventName, custom_event: CustomEvent) -> To
7676

7777
#base
7878

79-
impl ::std::ops::Deref for #ident{
80-
type Target = #inner_type;
81-
82-
fn deref(&self) -> &Self::Target {
83-
&self.0
84-
}
85-
}
86-
8779
impl ::std::convert::AsRef<::yew::web_sys::Event> for #ident {
8880
fn as_ref(&self) -> &::yew::web_sys::Event {
89-
&self.0
81+
self.0.as_ref()
9082
}
9183
}
9284

9385
impl ::std::convert::AsRef<::wasm_bindgen::JsValue> for #ident {
9486
fn as_ref(&self) -> &::wasm_bindgen::JsValue {
95-
&self.0
87+
self.0.as_ref()
9688
}
9789
}
9890

website/docs/concepts/html/elements.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,6 @@ html! {
421421
#### Traits implemented
422422

423423
The `custom_event` attribute macro implements the following traits:
424-
- [`Deref`](https://doc.rust-lang.org/std/ops/trait.Deref.html) where `Target` is the type wrapped by this Newtype.
425424
- [`AsRef<T>`](https://doc.rust-lang.org/std/convert/trait.AsRef.html) where `T` is:
426425
- [`JsValue`](https://rustwasm.github.io/wasm-bindgen/api/wasm_bindgen/struct.JsValue.html)
427426
- [`Event`](https://rustwasm.github.io/wasm-bindgen/api/web_sys/struct.Event.html)

0 commit comments

Comments
 (0)