ih_muse_proto/
element_kind.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
// crates/ih-muse-proto/src/element_kind.rs

use serde::{Deserialize, Serialize};

use crate::types::*;
use crate::utils::deterministic_u64_from_str;

#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
pub struct ElementKindRegistration {
    id: ElementKindId,
    pub code: String,
    parent_id: Option<ElementKindId>,
    pub name: String,
    pub description: String,
    forwarded: bool,
}

impl ElementKindRegistration {
    pub fn new(code: &str, parent_code: Option<&str>, name: &str, description: &str) -> Self {
        Self {
            id: deterministic_u64_from_str(code),
            code: code.to_string(),
            parent_id: parent_code.map(deterministic_u64_from_str),
            name: name.to_string(),
            description: description.to_string(),
            forwarded: false,
        }
    }
}