Skip to main content

sim_expr_tree_core/
name.rs

1use sim_table_core::is_legal_table_segment;
2
3use crate::NamespaceError;
4
5/// A validated finite namespace child name.
6#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
7pub struct NamespaceName(String);
8
9impl NamespaceName {
10    /// Validate `value` through the canonical Table segment predicate.
11    pub fn new(value: impl Into<String>) -> Result<Self, NamespaceError> {
12        let value = value.into();
13        if !is_legal_table_segment(&value) {
14            return Err(NamespaceError::IllegalName(value));
15        }
16        Ok(Self(value))
17    }
18
19    /// Borrow the stored child name.
20    pub fn as_str(&self) -> &str {
21        &self.0
22    }
23}
24
25impl std::fmt::Display for NamespaceName {
26    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
27        f.write_str(&self.0)
28    }
29}
30
31/// Generated-name counter families are scoped per parent directory.
32#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
33pub enum GeneratedNameKind {
34    /// Durable calculation cell names.
35    Cell,
36    /// Durable child directory names.
37    Dir,
38}
39
40impl GeneratedNameKind {
41    pub(crate) fn prefix(self) -> &'static str {
42        match self {
43            Self::Cell => "cell",
44            Self::Dir => "dir",
45        }
46    }
47}