use std::fmt;
#[derive(Clone, Default)]
pub struct AliasContext;
impl AliasContext {
pub fn new() -> Self {
Self
}
pub fn set_brackets(&self, _brackets: (&'static str, &'static str)) {}
}
pub trait Aliasing: fmt::Debug + 'static {
fn aliased(&self) -> Aliased<'_, Self> {
Aliased { val: self }
}
fn alias_prefix(_prefix: &str) {}
fn alias_numbered(&self) -> &Self {
self
}
fn alias_named(&self, _name: &str) -> &Self {
self
}
}
impl<T> Aliasing for T where T: fmt::Debug + 'static {}
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct Aliased<'v, T: ?Sized> {
val: &'v T,
}
impl<T: ?Sized + fmt::Debug> fmt::Debug for Aliased<'_, T> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt::Debug::fmt(self.val, f)
}
}
pub mod contextual {
use std::fmt;
pub use super::AliasContext;
pub trait Aliasing: fmt::Debug + 'static {
fn aliased<'v, 'c>(&'v self, ctx: &'c AliasContext) -> Aliased<'v, 'c, Self> {
Aliased { val: self, ctx }
}
fn alias_prefix(_ctx: &AliasContext, _prefix: &str) {}
fn alias_numbered(&self, _ctx: &AliasContext) -> &Self {
self
}
fn alias_named(&self, _ctx: &AliasContext, _name: &str) -> &Self {
self
}
}
impl<T> Aliasing for T where T: fmt::Debug + 'static {}
#[derive(Clone)]
pub struct Aliased<'v, 'c, T: ?Sized> {
val: &'v T,
ctx: &'c AliasContext,
}
impl<T: ?Sized + fmt::Debug> fmt::Debug for Aliased<'_, '_, T> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let _ = self.ctx;
fmt::Debug::fmt(self.val, f)
}
}
impl<'v, 'c, T: ?Sized + Eq> Eq for Aliased<'v, 'c, T> {}
impl<'v, 'c, T: ?Sized + Ord> Ord for Aliased<'v, 'c, T> {
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
self.val.cmp(other.val)
}
}
impl<'v, 'c, T: ?Sized + PartialOrd> PartialOrd for Aliased<'v, 'c, T> {
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
self.val.partial_cmp(other.val)
}
}
impl<'v, 'c, T: ?Sized + PartialEq> PartialEq for Aliased<'v, 'c, T> {
fn eq(&self, other: &Self) -> bool {
self.val.eq(other.val)
}
}
impl<'v, 'c, T: ?Sized + std::hash::Hash> std::hash::Hash for Aliased<'v, 'c, T> {
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
self.val.hash(state);
}
}
}