ninja_files_data2/variable_id/
mod.rs

1use std::borrow::Cow;
2
3mod as_ref;
4//mod try_from;
5
6#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
7pub struct VariableId(Cow<'static, str>);
8
9#[derive(Clone, Debug)]
10pub struct InvalidVariableId(pub Cow<'static, str>);
11
12impl VariableId {
13    pub const fn is_valid(_: &str) -> bool {
14        true
15    }
16    pub fn try_create<Id>(id: Id) -> Result<Self, InvalidVariableId>
17    where
18        Id: AsRef<str>,
19    {
20        Ok(VariableId(Cow::Owned(id.as_ref().into())))
21    }
22
23    pub const fn unsafe_create(id: &'static str) -> Self {
24        if Self::is_valid(id) {
25            VariableId(Cow::Borrowed(id))
26        } else {
27            panic!("Invalid rule id");
28        }
29    }
30}