This commit extracts Tag, Span, Text, as well as source-related debug facilities into a new crate called nu_source. This change is much bigger than one might have expected because the previous code relied heavily on implementing inherent methods on `Tagged<T>` and `Spanned<T>`, which is no longer possible. As a result, this change creates more concrete types instead of using `Tagged<T>`. One notable example: Tagged<Value> became Value, and Value became UntaggedValue. This change clarifies the intent of the code in many places, but it does make it a big change.
39 lines
925 B
Rust
39 lines
925 B
Rust
use crate::prelude::*;
|
|
use nu_source::{DebugDocBuilder, Spanned, SpannedItem, Tagged};
|
|
|
|
pub trait ShellTypeName {
|
|
fn type_name(&self) -> &'static str;
|
|
}
|
|
|
|
impl<T: ShellTypeName> ShellTypeName for Spanned<T> {
|
|
fn type_name(&self) -> &'static str {
|
|
self.item.type_name()
|
|
}
|
|
}
|
|
|
|
impl<T: ShellTypeName> ShellTypeName for &T {
|
|
fn type_name(&self) -> &'static str {
|
|
(*self).type_name()
|
|
}
|
|
}
|
|
|
|
pub trait SpannedTypeName {
|
|
fn spanned_type_name(&self) -> Spanned<&'static str>;
|
|
}
|
|
|
|
impl<T: ShellTypeName + HasSpan> SpannedTypeName for T {
|
|
fn spanned_type_name(&self) -> Spanned<&'static str> {
|
|
self.type_name().spanned(self.span())
|
|
}
|
|
}
|
|
|
|
impl<T: ShellTypeName> SpannedTypeName for Tagged<T> {
|
|
fn spanned_type_name(&self) -> Spanned<&'static str> {
|
|
self.item.type_name().spanned(self.tag.span)
|
|
}
|
|
}
|
|
|
|
pub trait PrettyType {
|
|
fn pretty_type(&self) -> DebugDocBuilder;
|
|
}
|