1use crate::{ImmutableString, Position};
4#[cfg(feature = "no_std")]
5use std::prelude::v1::*;
6use std::{borrow::Borrow, fmt, hash::Hash};
7
8#[derive(Clone, Eq, PartialEq, Hash)]
11pub struct Ident {
12 pub name: ImmutableString,
14 pub pos: Position,
16}
17
18impl fmt::Debug for Ident {
19 #[cold]
20 #[inline(never)]
21 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
22 write!(f, "{:?}", self.name)?;
23 if !self.pos.is_none() {
24 write!(f, " @ {:?}", self.pos)?;
25 }
26 Ok(())
27 }
28}
29
30impl Borrow<str> for Ident {
31 #[inline(always)]
32 #[must_use]
33 fn borrow(&self) -> &str {
34 self.name.as_ref()
35 }
36}
37
38impl AsRef<str> for Ident {
39 #[inline(always)]
40 #[must_use]
41 fn as_ref(&self) -> &str {
42 self.name.as_ref()
43 }
44}
45
46impl Ident {
47 #[inline(always)]
49 #[must_use]
50 pub fn as_str(&self) -> &str {
51 &self.name
52 }
53 #[inline(always)]
55 #[must_use]
56 pub fn is_empty(&self) -> bool {
57 self.name.is_empty()
58 }
59}