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(idx: usize) -> Name
pub fn generate_new_name(idx: usize) -> Name
Generates a new name that attempts to be unique. Should only be used when body lowering and creating desugared locals and labels. The caller is responsible for picking an index that is stable across re-executions
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 Extend<Name> for ModPath
impl Extend<Name> for ModPath
source§fn extend<T>(&mut self, iter: T)where
T: IntoIterator<Item = Name>,
fn extend<T>(&mut self, iter: T)where
T: IntoIterator<Item = Name>,
source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one
)source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one
)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 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 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
source§impl<T> Cast for T
impl<T> Cast for T
source§fn cast<U>(self, interner: <U as HasInterner>::Interner) -> Uwhere
Self: CastTo<U>,
U: HasInterner,
fn cast<U>(self, interner: <U as HasInterner>::Interner) -> Uwhere
Self: CastTo<U>,
U: HasInterner,
U
using CastTo
.source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.