diff --git a/yew-macro/tests/macro/html-tag-fail.stderr b/yew-macro/tests/macro/html-tag-fail.stderr
index 1571cb83e14..d13496e52fd 100644
--- a/yew-macro/tests/macro/html-tag-fail.stderr
+++ b/yew-macro/tests/macro/html-tag-fail.stderr
@@ -204,10 +204,10 @@ error[E0308]: mismatched types
--> $DIR/html-tag-fail.rs:32:20
|
32 | html! { };
- | ^^^^^^^ expected struct `yew::callback::Callback`, found integer
+ | ^^^^^^^ expected enum `yew::callback::Callback`, found integer
|
- = note: expected struct `yew::callback::Callback`
- found type `{integer}`
+ = note: expected enum `yew::callback::Callback`
+ found type `{integer}`
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0308]: mismatched types
@@ -216,8 +216,8 @@ error[E0308]: mismatched types
33 | html! { };
| ^^^^^^^ expected struct `web_sys::features::gen_MouseEvent::MouseEvent`, found struct `std::string::String`
|
- = note: expected struct `yew::callback::Callback`
- found struct `yew::callback::Callback`
+ = note: expected enum `yew::callback::Callback`
+ found enum `yew::callback::Callback`
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0599]: no method named `to_string` found for struct `NotToString` in the current scope
diff --git a/yew/src/callback.rs b/yew/src/callback.rs
index 6be69d9c97a..eb466bf39c8 100644
--- a/yew/src/callback.rs
+++ b/yew/src/callback.rs
@@ -1,5 +1,6 @@
-//! This module contains structs to interact with `Scope`s.
+//! This module contains data types for interacting with `Scope`s.
+use std::cell::RefCell;
use std::fmt;
use std::rc::Rc;
@@ -10,36 +11,73 @@ use std::rc::Rc;
/// Callbacks should be used from JS callbacks or `setTimeout` calls.
///
/// `Rc` wrapper used to make it clonable.
-pub struct Callback(Rc);
+pub enum Callback {
+ /// A callback that can be called multiple times
+ Callback(Rc),
+ /// A callback that will only be called once. Panics if it is called again
+ CallbackOnce(Rc>),
+}
+
+type CallbackOnce = RefCell