From ca8f8c2166f47674bf7d3b531784a3498c1449e5 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Wed, 24 Aug 2022 12:26:56 -0500 Subject: [PATCH] perf(error): Allow custmizing formatting For now, there isn't much a custom implementation can do. Going from `Rich` to `Null` drops about 6 KiB from the binary This is a part of #1365 and #1384 --- src/builder/mod.rs | 2 +- src/builder/styled_str.rs | 6 +- src/error/context.rs | 41 ++++ src/error/format.rs | 448 ++++++++++++++++++++++++++++++++++++++ src/error/mod.rs | 423 ++++------------------------------- tests/builder/error.rs | 99 ++++++++- 6 files changed, 637 insertions(+), 382 deletions(-) create mode 100644 src/error/format.rs diff --git a/src/builder/mod.rs b/src/builder/mod.rs index b717d598f983..a450cbee4087 100644 --- a/src/builder/mod.rs +++ b/src/builder/mod.rs @@ -33,6 +33,7 @@ pub use possible_value::PossibleValue; pub use range::ValueRange; pub use resettable::IntoResettable; pub use resettable::Resettable; +pub use styled_str::StyledStr; pub use value_hint::ValueHint; pub use value_parser::_AutoValueParser; pub use value_parser::via_prelude; @@ -55,7 +56,6 @@ pub use value_parser::_AnonymousValueParser; #[allow(unused_imports)] pub(crate) use self::str::Inner as StrInner; -pub(crate) use self::styled_str::StyledStr; pub(crate) use action::CountType; pub(crate) use arg::render_arg_val; pub(crate) use arg_settings::{ArgFlags, ArgSettings}; diff --git a/src/builder/styled_str.rs b/src/builder/styled_str.rs index ad2a697bb90e..afe2545a3ffe 100644 --- a/src/builder/styled_str.rs +++ b/src/builder/styled_str.rs @@ -1,10 +1,12 @@ +/// Terminal-styling container #[derive(Clone, Default, Debug, PartialEq, Eq)] -pub(crate) struct StyledStr { +pub struct StyledStr { pieces: Vec<(Option