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
33
34
35
36
37
38
39
40
41
42
43
44
45
mod action;
mod breakpoint;
mod classes;
mod context;
mod global_close;
mod orientation;
mod position;
mod size;
mod space;

pub use action::*;
pub use breakpoint::*;
pub use classes::*;
pub use context::*;
pub use global_close::*;
pub use orientation::*;
pub use position::*;
pub use size::*;
pub use space::*;
use std::fmt::{Debug, Display, Formatter};

pub fn random_id() -> String {
    uuid::Uuid::new_v4().to_string()
}

#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub struct Id(uuid::Uuid);

impl Id {
    /// Get a new, random ID
    pub fn new() -> Id {
        Id(uuid::Uuid::new_v4())
    }
}

impl Display for Id {
    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
        std::fmt::Display::fmt(&self.0, f)
    }
}

#[yew::hook]
pub fn use_id() -> yew::UseStateHandle<Id> {
    yew::use_state_eq(Id::new)
}