Skip to main content

Name

Enum Name 

Source
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

Source

pub fn str(s: impl Into<String>) -> Self

Create a simple string name (no parent).

Source

pub fn append_str(self, s: impl Into<String>) -> Self

Append a string component to this name.

Source

pub fn append_num(self, n: u64) -> Self

Append a numeric component to this name.

Source

pub fn is_anonymous(&self) -> bool

Check if this is the anonymous name.

Source

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").

Source

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.

Source

pub fn last_str(&self) -> Option<&str>

Return the last string component of this name, if any.

For Nat.add, returns Some("add").

Source

pub fn last_num(&self) -> Option<u64>

Return the last numeric component, if any.

Source

pub fn root(&self) -> Option<&str>

Return the root (top-level) component as a string.

For Nat.add.comm, returns "Nat".

Source

pub fn prefix(&self) -> Name

Return the parent name (prefix with last component removed).

Source

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.

Source

pub fn components(&self) -> Vec<String>

Collect all components from root to leaf.

Returns a vector of (is_num, string_or_num) pairs.

Source

pub fn from_components(comps: &[String]) -> Self

Reconstruct a Name from a list of string components.

Numeric strings are converted to Num components.

Source

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.

Source

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.

Source

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.

Source

pub fn with_suffix(self, suffix: impl Into<String>) -> Self

Append a suffix string to this name.

Source

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.

Source

pub fn prepend(self, prefix: Name) -> Self

Return a new name with the given prefix prepended.

Source

pub fn is_str_name(&self) -> bool

Check whether this name is a string name (last component is a string).

Source

pub fn is_num_name(&self) -> bool

Check whether this name is a numeric name (last component is a number).

Trait Implementations§

Source§

impl Clone for Name

Source§

fn clone(&self) -> Name

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Name

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Name

Source§

fn default() -> Name

Returns the “default value” for a type. Read more
Source§

impl Display for Name

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl FromIterator<Name> for NameSet

Source§

fn from_iter<I: IntoIterator<Item = Name>>(iter: I) -> Self

Creates a value from an iterator. Read more
Source§

impl Hash for Name

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl Ord for Name

Source§

fn cmp(&self, other: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for Name

Source§

fn eq(&self, other: &Name) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for Name

Source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Eq for Name

Source§

impl StructuralPartialEq for Name

Auto Trait Implementations§

§

impl Freeze for Name

§

impl RefUnwindSafe for Name

§

impl Send for Name

§

impl Sync for Name

§

impl Unpin for Name

§

impl UnsafeUnpin for Name

§

impl UnwindSafe for Name

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.