sim_expr_tree_core/
name.rs1use sim_table_core::is_legal_table_segment;
2
3use crate::NamespaceError;
4
5#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
7pub struct NamespaceName(String);
8
9impl NamespaceName {
10 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 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#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
33pub enum GeneratedNameKind {
34 Cell,
36 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}