yew_struct_component/
lib.rs

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
//! Define [Yew](https://yew.rs/) components using structs.

use std::{collections::HashMap, ops::Deref};

use yew::{html::IntoPropValue, AttrValue};
pub use yew_struct_component_macro::*;

#[derive(Clone, Debug, PartialEq)]
pub struct Attributes(HashMap<AttrValue, AttrValue>);

impl Deref for Attributes {
    type Target = HashMap<AttrValue, AttrValue>;

    fn deref(&self) -> &Self::Target {
        &self.0
    }
}

impl IntoPropValue<Attributes> for HashMap<AttrValue, AttrValue> {
    fn into_prop_value(self) -> Attributes {
        Attributes(self)
    }
}

impl<const N: usize> IntoPropValue<Attributes> for [(AttrValue, AttrValue); N] {
    fn into_prop_value(self) -> Attributes {
        Attributes(HashMap::from_iter(self))
    }
}