use std::fmt;
use sway_types::{Span, Spanned};
use super::declaration_engine::de_look_up_decl_id;
#[derive(Debug, Eq)]
pub struct DeclarationId(usize, Span);
impl Clone for DeclarationId {
fn clone(&self) -> Self {
Self(self.0, self.1.clone())
}
}
impl PartialEq for DeclarationId {
fn eq(&self, other: &Self) -> bool {
de_look_up_decl_id(self.clone()) == de_look_up_decl_id(other.clone())
}
}
impl fmt::Display for DeclarationId {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(&de_look_up_decl_id(self.clone()).to_string())
}
}
impl std::ops::Deref for DeclarationId {
type Target = usize;
fn deref(&self) -> &Self::Target {
&self.0
}
}
#[allow(clippy::from_over_into)]
impl Into<usize> for DeclarationId {
fn into(self) -> usize {
self.0
}
}
impl Spanned for DeclarationId {
fn span(&self) -> Span {
self.1.clone()
}
}
impl DeclarationId {
pub(super) fn new(index: usize, span: Span) -> DeclarationId {
DeclarationId(index, span)
}
}