pub enum Name {
Anonymous,
Str(Box<Name>, String),
Num(Box<Name>, u64),
}Expand description
A hierarchical name.
Names are used to identify constants, inductives, and other declarations.
They form a tree structure: Nat.add.comm is represented as
Str(Str(Str(Anonymous, "Nat"), "add"), "comm").
Variants§
Anonymous
The anonymous (root) name.
Str(Box<Name>, String)
A string component: parent name + string.
Num(Box<Name>, u64)
A numeric component: parent name + number.
Implementations§
Source§impl Name
impl Name
Sourcepub fn append_str(self, s: impl Into<String>) -> Self
pub fn append_str(self, s: impl Into<String>) -> Self
Append a string component to this name.
Sourcepub fn append_num(self, n: u64) -> Self
pub fn append_num(self, n: u64) -> Self
Append a numeric component to this name.
Sourcepub fn is_anonymous(&self) -> bool
pub fn is_anonymous(&self) -> bool
Check if this is the anonymous name.
Sourcepub fn from_str(s: &str) -> Self
pub fn from_str(s: &str) -> Self
Create a Name from a dot-separated string.
Name::from_str("Nat.add.comm") produces the same as
Name::str("Nat").append_str("add").append_str("comm").
Sourcepub fn depth(&self) -> usize
pub fn depth(&self) -> usize
Returns the depth (number of components) of this name.
Anonymous has depth 0, Name::str("Nat") has depth 1,
Name::str("Nat").append_str("add") has depth 2.
Sourcepub fn last_str(&self) -> Option<&str>
pub fn last_str(&self) -> Option<&str>
Return the last string component of this name, if any.
For Nat.add, returns Some("add").
Sourcepub fn root(&self) -> Option<&str>
pub fn root(&self) -> Option<&str>
Return the root (top-level) component as a string.
For Nat.add.comm, returns "Nat".
Sourcepub fn has_prefix(&self, prefix: &Name) -> bool
pub fn has_prefix(&self, prefix: &Name) -> bool
Check whether this name has prefix as a (strict) prefix.
Nat.add.comm.has_prefix(Nat) is true.
Sourcepub fn components(&self) -> Vec<String>
pub fn components(&self) -> Vec<String>
Collect all components from root to leaf.
Returns a vector of (is_num, string_or_num) pairs.
Sourcepub fn from_components(comps: &[String]) -> Self
pub fn from_components(comps: &[String]) -> Self
Reconstruct a Name from a list of string components.
Numeric strings are converted to Num components.
Sourcepub fn replace_last(self, new_last: impl Into<String>) -> Self
pub fn replace_last(self, new_last: impl Into<String>) -> Self
Replace the last string component with new_last.
If the name ends in a numeric component, appends new_last instead.
Sourcepub fn freshen(self, suffix: u64) -> Self
pub fn freshen(self, suffix: u64) -> Self
Produce a “fresh” version of this name by appending a suffix number.
Used to avoid name collisions during elaboration.
Sourcepub fn in_namespace(&self, ns: &Name) -> bool
pub fn in_namespace(&self, ns: &Name) -> bool
Check whether this name is in the given namespace.
A name is in namespace ns if it has ns as a strict prefix.
Sourcepub fn with_suffix(self, suffix: impl Into<String>) -> Self
pub fn with_suffix(self, suffix: impl Into<String>) -> Self
Append a suffix string to this name.
Sourcepub fn to_ident_string(&self) -> String
pub fn to_ident_string(&self) -> String
Convert to a string suitable for use as a Rust identifier.
Dots and special characters are replaced with underscores.
Sourcepub fn is_str_name(&self) -> bool
pub fn is_str_name(&self) -> bool
Check whether this name is a string name (last component is a string).
Sourcepub fn is_num_name(&self) -> bool
pub fn is_num_name(&self) -> bool
Check whether this name is a numeric name (last component is a number).