2021-12-17 09:07:13 +01:00
|
|
|
//! Module defining script identifiers.
|
|
|
|
|
2022-08-13 12:07:42 +02:00
|
|
|
use crate::{ImmutableString, Position};
|
2021-12-17 09:07:13 +01:00
|
|
|
#[cfg(feature = "no_std")]
|
|
|
|
use std::prelude::v1::*;
|
2022-03-05 10:57:23 +01:00
|
|
|
use std::{
|
|
|
|
fmt,
|
|
|
|
hash::Hash,
|
|
|
|
ops::{Deref, DerefMut},
|
|
|
|
};
|
2021-12-17 09:07:13 +01:00
|
|
|
|
|
|
|
/// _(internals)_ An identifier containing a name and a [position][Position].
|
|
|
|
/// Exported under the `internals` feature only.
|
|
|
|
#[derive(Clone, Eq, PartialEq, Hash)]
|
|
|
|
pub struct Ident {
|
|
|
|
/// Identifier name.
|
2022-08-13 12:07:42 +02:00
|
|
|
pub name: ImmutableString,
|
2021-12-17 09:07:13 +01:00
|
|
|
/// Position.
|
|
|
|
pub pos: Position,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl fmt::Debug for Ident {
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
|
|
write!(f, "{:?}", self.name)?;
|
|
|
|
self.pos.debug_print(f)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl AsRef<str> for Ident {
|
|
|
|
#[inline(always)]
|
|
|
|
fn as_ref(&self) -> &str {
|
|
|
|
self.name.as_ref()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-05 10:57:23 +01:00
|
|
|
impl Deref for Ident {
|
2022-08-13 12:07:42 +02:00
|
|
|
type Target = ImmutableString;
|
2022-03-05 10:57:23 +01:00
|
|
|
|
|
|
|
#[inline(always)]
|
|
|
|
fn deref(&self) -> &Self::Target {
|
|
|
|
&self.name
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl DerefMut for Ident {
|
|
|
|
#[inline(always)]
|
|
|
|
fn deref_mut(&mut self) -> &mut Self::Target {
|
|
|
|
&mut self.name
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-17 09:07:13 +01:00
|
|
|
impl Ident {
|
2022-03-05 10:57:23 +01:00
|
|
|
/// Get the name of the identifier as a string slice.
|
2021-12-17 09:07:13 +01:00
|
|
|
#[inline(always)]
|
2022-07-27 12:04:59 +02:00
|
|
|
#[must_use]
|
2021-12-17 09:07:13 +01:00
|
|
|
pub fn as_str(&self) -> &str {
|
|
|
|
self.name.as_str()
|
|
|
|
}
|
|
|
|
}
|