use core::borrow::Borrow;
use crate::{Span, Spanned};
#[derive(Clone, Debug)]
pub struct Identifier<'a> {
pub value: &'a str,
pub span: Span,
}
impl<'a> PartialEq for Identifier<'a> {
fn eq(&self, other: &Self) -> bool {
self.value == other.value
}
}
impl<'a> Eq for Identifier<'a> {}
impl<'a> PartialOrd for Identifier<'a> {
fn partial_cmp(&self, other: &Self) -> Option<core::cmp::Ordering> {
Some(self.cmp(other))
}
}
impl<'a> Ord for Identifier<'a> {
fn cmp(&self, other: &Self) -> core::cmp::Ordering {
self.value.cmp(other.value)
}
}
impl<'a> alloc::fmt::Display for Identifier<'a> {
fn fmt(&self, f: &mut alloc::fmt::Formatter<'_>) -> alloc::fmt::Result {
self.value.fmt(f)
}
}
impl<'a> Borrow<str> for Identifier<'a> {
fn borrow(&self) -> &str {
self.value
}
}
impl<'a> Identifier<'a> {
pub fn new(value: &'a str, span: Span) -> Self {
Identifier { value, span }
}
pub fn as_str(&self) -> &'a str {
self.value
}
}
impl<'a> core::ops::Deref for Identifier<'a> {
type Target = str;
fn deref(&self) -> &'a Self::Target {
self.value
}
}
impl<'a> Spanned for Identifier<'a> {
fn span(&self) -> Span {
self.span.span()
}
}