Unnamed repository; edit this file 'description' to name the repository.
implement custom `Debug` for `MiniCore`
When the contents correspond to the default, just output
`MiniCore("<default>")` instead of the whole thing.
Helps reduce the length of the debug output in the common case.
| -rw-r--r-- | crates/ide-db/src/lib.rs | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/crates/ide-db/src/lib.rs b/crates/ide-db/src/lib.rs index 99af1c32d8..6b72a30339 100644 --- a/crates/ide-db/src/lib.rs +++ b/crates/ide-db/src/lib.rs @@ -385,7 +385,7 @@ pub enum Severity { Allow, } -#[derive(Debug, Clone, Copy)] +#[derive(Clone, Copy)] pub struct MiniCore<'a>(&'a str); impl<'a> MiniCore<'a> { @@ -400,6 +400,15 @@ impl<'a> MiniCore<'a> { } } +impl std::fmt::Debug for MiniCore<'_> { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.debug_tuple("MiniCore") + // don't print the whole contents if they correspond to the default + .field(if self.0 == test_utils::MiniCore::RAW_SOURCE { &"<default>" } else { &self.0 }) + .finish() + } +} + impl<'a> Default for MiniCore<'a> { #[inline] fn default() -> Self { |