pub struct Name(/* private fields */);Expand description
Name is a wrapper around string, which is used in hir for both references
and declarations. In theory, names should also carry hygiene info, but we are
not there yet!
Note that Name holds and prints escaped name i.e. prefixed with “r#” when it
is a raw identifier. Use unescaped() when you need the
name without “r#”.
Implementations§
source§impl Name
impl Name
pub fn new_tuple_field(idx: usize) -> Name
pub fn new_lifetime(lt: &Lifetime) -> Name
sourcepub const fn missing() -> Name
pub const fn missing() -> Name
A fake name for things missing in the source code.
For example, impl Foo for {} should be treated as a trait impl for a
type with a missing name. Similarly, struct S { : u32 } should have a
single field with a missing name.
Ideally, we want a gensym semantics for missing names – each missing
name is equal only to itself. It’s not clear how to implement this in
salsa though, so we punt on that bit for a moment.
sourcepub fn is_missing(&self) -> bool
pub fn is_missing(&self) -> bool
Returns true if this is a fake name for things missing in the source code. See
missing() for details.
Use this method instead of comparing with Self::missing() as missing names
(ideally should) have a gensym semantics.
sourcepub fn generate_new_name() -> Name
pub fn generate_new_name() -> Name
Generates a new name which is only equal to itself, by incrementing a counter. Due its implementation, it should not be used in things that salsa considers, like type names or field names, and it should be only used in names of local variables and labels and similar things.
sourcepub fn as_tuple_index(&self) -> Option<usize>
pub fn as_tuple_index(&self) -> Option<usize>
Returns the tuple index this name represents if it is a tuple field.
sourcepub fn as_text(&self) -> Option<SmolStr>
pub fn as_text(&self) -> Option<SmolStr>
Returns the text this name represents if it isn’t a tuple field.
sourcepub fn as_str(&self) -> Option<&str>
pub fn as_str(&self) -> Option<&str>
Returns the text this name represents if it isn’t a tuple field.
sourcepub fn to_smol_str(&self) -> SmolStr
pub fn to_smol_str(&self) -> SmolStr
Returns the textual representation of this name as a [SmolStr].
Prefer using this over ToString::to_string if possible as this conversion is cheaper in
the general case.
pub fn unescaped(&self) -> UnescapedName<'_>
pub fn is_escaped(&self) -> bool
pub fn display<'a>(&'a self, db: &dyn ExpandDatabase) -> impl Display + 'a
Trait Implementations§
source§impl Ord for Name
impl Ord for Name
source§impl PartialEq for Name
impl PartialEq for Name
source§impl PartialOrd for Name
impl PartialOrd for Name
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self and other) and is used by the <=
operator. Read moreimpl Eq for Name
impl StructuralEq for Name
impl StructuralPartialEq for Name
Auto Trait Implementations§
impl RefUnwindSafe for Name
impl Send for Name
impl Sync for Name
impl Unpin for Name
impl UnwindSafe for Name
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Cast for T
impl<T> Cast for T
§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.