1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
use yew::prelude::*;

#[derive(Clone, PartialEq, Default, Debug)]
pub struct Action {
    pub label: String,
    pub callback: Callback<()>,
}

impl Action {
    pub fn new<S>(label: S, callback: Callback<()>) -> Self
    where
        S: ToString,
    {
        Self {
            label: label.to_string(),
            callback,
        }
    }
}

pub trait IntoAction {
    fn into_action<S: ToString>(self, label: S) -> Action;
}

impl IntoAction for Callback<()> {
    fn into_action<S>(self, label: S) -> Action
    where
        S: ToString,
    {
        Action::new(label, self)
    }
}