allow str from to convert more things to string (#2977)

* allow str from to convert more things to string

* fixed FileSize so it reports with units configured

* added tests
This commit is contained in:
Darren Schroeder
2021-01-29 07:43:35 -06:00
committed by GitHub
parent d0a2a02eea
commit 47c4b8e88a
20 changed files with 638 additions and 441 deletions

View File

@ -8,8 +8,8 @@ pub use self::meta::{
IntoSpanned, Span, Spanned, SpannedItem, Tag, Tagged, TaggedItem,
};
pub use self::pretty::{
b, DebugDoc, DebugDocBuilder, PrettyDebug, PrettyDebugRefineKind, PrettyDebugWithSource,
ShellAnnotation,
DbgDocBldr, DebugDoc, DebugDocBuilder, PrettyDebug, PrettyDebugRefineKind,
PrettyDebugWithSource, ShellAnnotation,
};
pub use self::term_colored::TermColored;
pub use self::text::Text;

View File

@ -1,4 +1,4 @@
use crate::pretty::{b, DebugDocBuilder, PrettyDebugWithSource};
use crate::pretty::{DbgDocBldr, DebugDocBuilder, PrettyDebugWithSource};
use crate::text::Text;
use derive_new::new;
@ -738,7 +738,7 @@ where
impl PrettyDebugWithSource for Option<Span> {
fn pretty_debug(&self, source: &str) -> DebugDocBuilder {
match self {
None => b::description("no span"),
None => DbgDocBldr::description("no span"),
Some(span) => span.pretty_debug(source),
}
}
@ -752,9 +752,11 @@ impl HasFallibleSpan for Option<Span> {
impl PrettyDebugWithSource for Span {
fn pretty_debug(&self, source: &str) -> DebugDocBuilder {
b::typed(
DbgDocBldr::typed(
"span",
b::keyword("for") + b::space() + b::description(format!("{:?}", self.slice(source))),
DbgDocBldr::keyword("for")
+ DbgDocBldr::space()
+ DbgDocBldr::description(format!("{:?}", self.slice(source))),
)
}
}
@ -771,7 +773,7 @@ where
{
fn pretty_debug(&self, source: &str) -> DebugDocBuilder {
match self {
None => b::description("nothing"),
None => DbgDocBldr::description("nothing"),
Some(v) => v.pretty_debug(v.span.slice(source)),
}
}
@ -792,7 +794,7 @@ where
{
fn pretty_debug(&self, source: &str) -> DebugDocBuilder {
match self {
None => b::description("nothing"),
None => DbgDocBldr::description("nothing"),
Some(d) => d.pretty_debug(source),
}
}

View File

@ -92,7 +92,7 @@ pub type PrettyDebugDoc =
pub type PrettyDebugDocBuilder = pretty::DocBuilder<'static, pretty::BoxAllocator, ShellAnnotation>;
pub use self::DebugDocBuilder as b;
pub use self::DebugDocBuilder as DbgDocBldr;
#[derive(Clone, new)]
pub struct DebugDocBuilder {
@ -102,15 +102,15 @@ pub struct DebugDocBuilder {
impl PrettyDebug for bool {
fn pretty(&self) -> DebugDocBuilder {
match self {
true => b::primitive("true"),
false => b::primitive("false"),
true => DbgDocBldr::primitive("true"),
false => DbgDocBldr::primitive("false"),
}
}
}
impl PrettyDebug for () {
fn pretty(&self) -> DebugDocBuilder {
b::primitive("nothing")
DbgDocBldr::primitive("nothing")
}
}
@ -172,7 +172,7 @@ impl DebugDocBuilder {
}
pub fn typed(kind: &str, value: DebugDocBuilder) -> DebugDocBuilder {
b::kind(kind) + b::delimit("[", value.group(), "]")
DbgDocBldr::kind(kind) + DbgDocBldr::delimit("[", value.group(), "]")
}
pub fn subtyped(
@ -180,10 +180,12 @@ impl DebugDocBuilder {
subkind: impl std::fmt::Display,
value: DebugDocBuilder,
) -> DebugDocBuilder {
b::delimit(
DbgDocBldr::delimit(
"(",
(b::kind(kind) + b::delimit("[", b::kind(format!("{}", subkind)), "]")).group()
+ b::space()
(DbgDocBldr::kind(kind)
+ DbgDocBldr::delimit("[", DbgDocBldr::kind(format!("{}", subkind)), "]"))
.group()
+ DbgDocBldr::space()
+ value.group(),
")",
)
@ -237,7 +239,7 @@ impl DebugDocBuilder {
) -> DebugDocBuilder {
match builder {
None => DebugDocBuilder::blank(),
Some(b) => b::option(before) + b + b::option(after),
Some(b) => DbgDocBldr::option(before) + b + DbgDocBldr::option(after),
}
}
@ -398,7 +400,7 @@ impl<T: PrettyDebug> PrettyDebugWithSource for T {
impl<T: PrettyDebugWithSource, E> PrettyDebugWithSource for Result<T, E> {
fn pretty_debug(&self, source: &str) -> DebugDocBuilder {
match self {
Err(_) => b::error("error"),
Err(_) => DbgDocBldr::error("error"),
Ok(val) => val.pretty_debug(source),
}
}