From 544c1af68cc506b5ca4f4487c077066a6ce235c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arkadiusz=20J=C4=99drzejewski?= Date: Thu, 26 Mar 2026 13:02:19 +0100 Subject: [PATCH 1/2] containers: add `ScoreDebug` and `Debug` Add `ScoreDebug` and `Debug` implementations. --- Cargo.lock | 1 + src/containers/BUILD | 5 +- src/containers/Cargo.toml | 5 ++ src/containers/fixed_capacity/queue.rs | 27 +++++++++ src/containers/fixed_capacity/string.rs | 16 ++++- src/containers/fixed_capacity/vec.rs | 14 +++++ src/containers/generic/queue.rs | 14 +++++ src/containers/generic/string.rs | 7 +++ src/containers/generic/vec.rs | 7 +++ src/containers/inline/option.rs | 10 ++++ src/containers/inline/queue.rs | 16 +++++ src/containers/inline/result.rs | 10 ++++ src/containers/inline/string.rs | 7 +++ src/containers/inline/vec.rs | 9 +++ src/log/score_log_fmt/fmt_impl.rs | 77 +++++++++++++++++-------- 15 files changed, 198 insertions(+), 27 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 3500492d..68f0d235 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7,6 +7,7 @@ name = "containers" version = "0.1.0" dependencies = [ "elementary", + "score_log", ] [[package]] diff --git a/src/containers/BUILD b/src/containers/BUILD index af9cb47e..9c544661 100644 --- a/src/containers/BUILD +++ b/src/containers/BUILD @@ -18,7 +18,10 @@ rust_library( srcs = glob(["**/*.rs"]), edition = "2021", visibility = ["//visibility:public"], - deps = ["//src/elementary"], + deps = [ + "//src/elementary", + "//src/log/score_log", + ], ) rust_test( diff --git a/src/containers/Cargo.toml b/src/containers/Cargo.toml index 18a071be..8601bc69 100644 --- a/src/containers/Cargo.toml +++ b/src/containers/Cargo.toml @@ -24,3 +24,8 @@ path = "lib.rs" [dependencies] elementary.workspace = true +# `score_log` introduces `std`. +score_log = { workspace = true, optional = true } + +[features] +default = ["score_log"] diff --git a/src/containers/fixed_capacity/queue.rs b/src/containers/fixed_capacity/queue.rs index 6cd3d594..9ada43e9 100644 --- a/src/containers/fixed_capacity/queue.rs +++ b/src/containers/fixed_capacity/queue.rs @@ -13,6 +13,7 @@ use crate::generic::queue::GenericQueue; use crate::storage::Heap; +use core::fmt; use core::ops; use elementary::{BasicAllocator, HeapAllocator, GLOBAL_ALLOCATOR}; @@ -64,6 +65,19 @@ impl ops::DerefMut for FixedCapacityQueueIn<'_, T, A> { } } +impl fmt::Debug for FixedCapacityQueueIn<'_, T, A> { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + fmt::Debug::fmt(&self.inner, f) + } +} + +#[cfg(feature = "score_log")] +impl score_log::fmt::ScoreDebug for FixedCapacityQueueIn<'_, T, A> { + fn fmt(&self, f: score_log::fmt::Writer, spec: &score_log::fmt::FormatSpec) -> score_log::fmt::Result { + score_log::fmt::ScoreDebug::fmt(&self.inner, f, spec) + } +} + /// A fixed-capacity queue, using global allocator. /// Refer to [`FixedCapacityQueueIn`] for more information. pub struct FixedCapacityQueue(FixedCapacityQueueIn<'static, T, HeapAllocator>); @@ -95,6 +109,19 @@ impl ops::DerefMut for FixedCapacityQueue { } } +impl fmt::Debug for FixedCapacityQueue { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + fmt::Debug::fmt(&self.0, f) + } +} + +#[cfg(feature = "score_log")] +impl score_log::fmt::ScoreDebug for FixedCapacityQueue { + fn fmt(&self, f: score_log::fmt::Writer, spec: &score_log::fmt::FormatSpec) -> score_log::fmt::Result { + score_log::fmt::ScoreDebug::fmt(&self.0, f, spec) + } +} + #[cfg(test)] mod tests { use super::*; diff --git a/src/containers/fixed_capacity/string.rs b/src/containers/fixed_capacity/string.rs index 7fba5943..de65abcc 100644 --- a/src/containers/fixed_capacity/string.rs +++ b/src/containers/fixed_capacity/string.rs @@ -98,6 +98,13 @@ impl fmt::Debug for FixedCapacityStringIn<'_, A> { } } +#[cfg(feature = "score_log")] +impl score_log::fmt::ScoreDebug for FixedCapacityStringIn<'_, A> { + fn fmt(&self, f: score_log::fmt::Writer, spec: &score_log::fmt::FormatSpec) -> score_log::fmt::Result { + score_log::fmt::ScoreDebug::fmt(self.as_str(), f, spec) + } +} + /// A fixed-capacity Unicode string, using global allocator. /// Refer to [`FixedCapacityStringIn`] for more information. pub struct FixedCapacityString(FixedCapacityStringIn<'static, HeapAllocator>); @@ -150,7 +157,14 @@ impl fmt::Display for FixedCapacityString { impl fmt::Debug for FixedCapacityString { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - fmt::Debug::fmt(self.0.as_str(), f) + fmt::Debug::fmt(&self.0, f) + } +} + +#[cfg(feature = "score_log")] +impl score_log::fmt::ScoreDebug for FixedCapacityString { + fn fmt(&self, f: score_log::fmt::Writer, spec: &score_log::fmt::FormatSpec) -> score_log::fmt::Result { + score_log::fmt::ScoreDebug::fmt(&self.0, f, spec) } } diff --git a/src/containers/fixed_capacity/vec.rs b/src/containers/fixed_capacity/vec.rs index 5679c164..c29eb5f6 100644 --- a/src/containers/fixed_capacity/vec.rs +++ b/src/containers/fixed_capacity/vec.rs @@ -85,6 +85,13 @@ impl fmt::Debug for FixedCapacityVecIn<'_, T, } } +#[cfg(feature = "score_log")] +impl score_log::fmt::ScoreDebug for FixedCapacityVecIn<'_, T, A> { + fn fmt(&self, f: score_log::fmt::Writer, spec: &score_log::fmt::FormatSpec) -> score_log::fmt::Result { + score_log::fmt::ScoreDebug::fmt(self.as_slice(), f, spec) + } +} + /// A fixed-capacity vector, using global allocator. /// Refer to [`FixedCapacityVecIn`] for more information. pub struct FixedCapacityVec(FixedCapacityVecIn<'static, T, HeapAllocator>); @@ -131,6 +138,13 @@ impl fmt::Debug for FixedCapacityVec { } } +#[cfg(feature = "score_log")] +impl score_log::fmt::ScoreDebug for FixedCapacityVec { + fn fmt(&self, f: score_log::fmt::Writer, spec: &score_log::fmt::FormatSpec) -> score_log::fmt::Result { + score_log::fmt::ScoreDebug::fmt(&self.0, f, spec) + } +} + #[cfg(test)] mod tests { use super::*; diff --git a/src/containers/generic/queue.rs b/src/containers/generic/queue.rs index 9cfdccae..4bd8c7ea 100644 --- a/src/containers/generic/queue.rs +++ b/src/containers/generic/queue.rs @@ -11,6 +11,7 @@ // SPDX-License-Identifier: Apache-2.0 // ******************************************************************************* +use core::fmt; use core::iter::FusedIterator; use core::marker::PhantomData; use core::mem::needs_drop; @@ -278,6 +279,19 @@ impl> GenericQueue { } } +impl> fmt::Debug for GenericQueue { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.debug_list().entries(self.iter()).finish() + } +} + +#[cfg(feature = "score_log")] +impl> score_log::fmt::ScoreDebug for GenericQueue { + fn fmt(&self, f: score_log::fmt::Writer, spec: &score_log::fmt::FormatSpec) -> score_log::fmt::Result { + score_log::fmt::DebugList::new(f, spec).entries(self.iter()).finish() + } +} + pub struct Iter<'a, T> { first: slice::Iter<'a, T>, second: slice::Iter<'a, T>, diff --git a/src/containers/generic/string.rs b/src/containers/generic/string.rs index a567d518..4e5e8bc0 100644 --- a/src/containers/generic/string.rs +++ b/src/containers/generic/string.rs @@ -137,6 +137,13 @@ impl> fmt::Debug for GenericString { } } +#[cfg(feature = "score_log")] +impl> score_log::fmt::ScoreDebug for GenericString { + fn fmt(&self, f: score_log::fmt::Writer, spec: &score_log::fmt::FormatSpec) -> score_log::fmt::Result { + score_log::fmt::ScoreDebug::fmt(self.as_str(), f, spec) + } +} + #[cfg(test)] mod tests { use super::*; diff --git a/src/containers/generic/vec.rs b/src/containers/generic/vec.rs index 13345bab..743c1d01 100644 --- a/src/containers/generic/vec.rs +++ b/src/containers/generic/vec.rs @@ -175,6 +175,13 @@ impl> fmt::Debug for GenericVec { } } +#[cfg(feature = "score_log")] +impl> score_log::fmt::ScoreDebug for GenericVec { + fn fmt(&self, f: score_log::fmt::Writer, spec: &score_log::fmt::FormatSpec) -> score_log::fmt::Result { + score_log::fmt::ScoreDebug::fmt(self.as_slice(), f, spec) + } +} + #[cfg(test)] mod tests { use super::*; diff --git a/src/containers/inline/option.rs b/src/containers/inline/option.rs index 196668ed..afa01d96 100644 --- a/src/containers/inline/option.rs +++ b/src/containers/inline/option.rs @@ -174,6 +174,16 @@ where } } +#[cfg(feature = "score_log")] +impl score_log::fmt::ScoreDebug for InlineOption +where + for<'a> Option<&'a T>: score_log::fmt::ScoreDebug, +{ + fn fmt(&self, f: score_log::fmt::Writer, spec: &score_log::fmt::FormatSpec) -> score_log::fmt::Result { + score_log::fmt::ScoreDebug::fmt(&self.as_ref(), f, spec) + } +} + #[cfg(test)] mod tests { use super::*; diff --git a/src/containers/inline/queue.rs b/src/containers/inline/queue.rs index 2c502948..048ef948 100644 --- a/src/containers/inline/queue.rs +++ b/src/containers/inline/queue.rs @@ -11,6 +11,7 @@ // SPDX-License-Identifier: Apache-2.0 // ******************************************************************************* +use core::fmt; use core::ops; use crate::generic::queue::GenericQueue; @@ -73,6 +74,21 @@ impl ops::DerefMut for InlineQueue } } +impl fmt::Debug for InlineQueue { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + fmt::Debug::fmt(&self.inner, f) + } +} + +#[cfg(feature = "score_log")] +impl score_log::fmt::ScoreDebug + for InlineQueue +{ + fn fmt(&self, f: score_log::fmt::Writer, spec: &score_log::fmt::FormatSpec) -> score_log::fmt::Result { + score_log::fmt::ScoreDebug::fmt(&self.inner, f, spec) + } +} + #[cfg(test)] mod tests { use std::collections::VecDeque; diff --git a/src/containers/inline/result.rs b/src/containers/inline/result.rs index 4286eaa2..d4e32e2f 100644 --- a/src/containers/inline/result.rs +++ b/src/containers/inline/result.rs @@ -188,6 +188,16 @@ where } } +#[cfg(feature = "score_log")] +impl score_log::fmt::ScoreDebug for InlineResult +where + for<'a> Result<&'a T, &'a E>: score_log::fmt::ScoreDebug, +{ + fn fmt(&self, f: score_log::fmt::Writer, spec: &score_log::fmt::FormatSpec) -> score_log::fmt::Result { + score_log::fmt::ScoreDebug::fmt(&self.as_ref(), f, spec) + } +} + #[cfg(test)] mod tests { use super::*; diff --git a/src/containers/inline/string.rs b/src/containers/inline/string.rs index f1e3b40f..df1bbe81 100644 --- a/src/containers/inline/string.rs +++ b/src/containers/inline/string.rs @@ -81,6 +81,13 @@ impl fmt::Debug for InlineString { } } +#[cfg(feature = "score_log")] +impl score_log::fmt::ScoreDebug for InlineString { + fn fmt(&self, f: score_log::fmt::Writer, spec: &score_log::fmt::FormatSpec) -> score_log::fmt::Result { + score_log::fmt::ScoreDebug::fmt(self.as_str(), f, spec) + } +} + #[cfg(test)] mod tests { use super::*; diff --git a/src/containers/inline/vec.rs b/src/containers/inline/vec.rs index 2dcefff5..c8481149 100644 --- a/src/containers/inline/vec.rs +++ b/src/containers/inline/vec.rs @@ -79,6 +79,15 @@ impl fmt::Debug for InlineVec score_log::fmt::ScoreDebug + for InlineVec +{ + fn fmt(&self, f: score_log::fmt::Writer, spec: &score_log::fmt::FormatSpec) -> score_log::fmt::Result { + score_log::fmt::ScoreDebug::fmt(self.as_slice(), f, spec) + } +} + #[cfg(test)] mod tests { use super::*; diff --git a/src/log/score_log_fmt/fmt_impl.rs b/src/log/score_log_fmt/fmt_impl.rs index d3b83179..d516f8ec 100644 --- a/src/log/score_log_fmt/fmt_impl.rs +++ b/src/log/score_log_fmt/fmt_impl.rs @@ -14,14 +14,14 @@ //! `ScoreDebug` implementations for common types. use crate::builders::{DebugList, DebugStruct, DebugTuple}; -use crate::fmt::{Error, Result, ScoreDebug, Writer}; +use crate::fmt::{Error, Result as FmtResult, ScoreDebug, Writer}; use crate::fmt_spec::{DisplayHint, FormatSpec}; use crate::DebugMap; macro_rules! impl_debug_for_t { ($t:ty, $fn:ident) => { impl ScoreDebug for $t { - fn fmt(&self, f: Writer, spec: &FormatSpec) -> Result { + fn fmt(&self, f: Writer, spec: &FormatSpec) -> FmtResult { f.$fn(self, spec) } } @@ -41,13 +41,13 @@ impl_debug_for_t!(u32, write_u32); impl_debug_for_t!(u64, write_u64); impl ScoreDebug for () { - fn fmt(&self, f: Writer, spec: &FormatSpec) -> Result { + fn fmt(&self, f: Writer, spec: &FormatSpec) -> FmtResult { f.write_str("()", spec) } } impl ScoreDebug for str { - fn fmt(&self, f: Writer, spec: &FormatSpec) -> Result { + fn fmt(&self, f: Writer, spec: &FormatSpec) -> FmtResult { match spec.get_display_hint() { DisplayHint::Debug => { let queue_spec = FormatSpec::new(); @@ -61,13 +61,13 @@ impl ScoreDebug for str { } impl ScoreDebug for String { - fn fmt(&self, f: Writer, spec: &FormatSpec) -> Result { + fn fmt(&self, f: Writer, spec: &FormatSpec) -> FmtResult { ScoreDebug::fmt(&self.as_str(), f, spec) } } impl ScoreDebug for core::str::Utf8Error { - fn fmt(&self, f: Writer, spec: &FormatSpec) -> Result { + fn fmt(&self, f: Writer, spec: &FormatSpec) -> FmtResult { let mut debug_struct = DebugStruct::new(f, spec, "Utf8Error"); debug_struct .field("valid_up_to", &self.valid_up_to()) @@ -77,7 +77,7 @@ impl ScoreDebug for core::str::Utf8Error { } impl ScoreDebug for std::string::FromUtf8Error { - fn fmt(&self, f: Writer, spec: &FormatSpec) -> Result { + fn fmt(&self, f: Writer, spec: &FormatSpec) -> FmtResult { let mut debug_struct = DebugStruct::new(f, spec, "FromUtf8Error"); debug_struct .field("bytes", &self.as_bytes()) @@ -87,7 +87,7 @@ impl ScoreDebug for std::string::FromUtf8Error { } impl ScoreDebug for core::time::Duration { - fn fmt(&self, f: Writer, spec: &FormatSpec) -> Result { + fn fmt(&self, f: Writer, spec: &FormatSpec) -> FmtResult { f.write_f64(&self.as_secs_f64(), spec)?; f.write_str("s", spec) } @@ -96,7 +96,7 @@ impl ScoreDebug for core::time::Duration { macro_rules! impl_debug_for_t_casted { ($ti:ty, $to:ty, $fn:ident) => { impl ScoreDebug for $ti { - fn fmt(&self, f: Writer, spec: &FormatSpec) -> Result { + fn fmt(&self, f: Writer, spec: &FormatSpec) -> FmtResult { let casted = <$to>::try_from(*self).map_err(|_| Error)?; f.$fn(&casted, spec) } @@ -114,57 +114,57 @@ impl_debug_for_t_casted!(usize, u32, write_u32); impl_debug_for_t_casted!(usize, u64, write_u64); impl ScoreDebug for &T { - fn fmt(&self, f: Writer, spec: &FormatSpec) -> Result { + fn fmt(&self, f: Writer, spec: &FormatSpec) -> FmtResult { ScoreDebug::fmt(&**self, f, spec) } } impl ScoreDebug for &mut T { - fn fmt(&self, f: Writer, spec: &FormatSpec) -> Result { + fn fmt(&self, f: Writer, spec: &FormatSpec) -> FmtResult { ScoreDebug::fmt(&**self, f, spec) } } impl ScoreDebug for [T] { - fn fmt(&self, f: Writer, spec: &FormatSpec) -> Result { + fn fmt(&self, f: Writer, spec: &FormatSpec) -> FmtResult { let mut debug_list = DebugList::new(f, spec); debug_list.entries(self.iter()).finish() } } impl ScoreDebug for [T; N] { - fn fmt(&self, f: Writer, spec: &FormatSpec) -> Result { + fn fmt(&self, f: Writer, spec: &FormatSpec) -> FmtResult { ScoreDebug::fmt(&&self[..], f, spec) } } impl ScoreDebug for core::array::TryFromSliceError { - fn fmt(&self, f: Writer, spec: &FormatSpec) -> Result { + fn fmt(&self, f: Writer, spec: &FormatSpec) -> FmtResult { let mut debug_tuple = DebugTuple::new(f, spec, "TryFromSliceError"); debug_tuple.field(&()).finish() } } impl ScoreDebug for Vec { - fn fmt(&self, f: Writer, spec: &FormatSpec) -> Result { + fn fmt(&self, f: Writer, spec: &FormatSpec) -> FmtResult { ScoreDebug::fmt(&**self, f, spec) } } impl ScoreDebug for std::rc::Rc { - fn fmt(&self, f: Writer, spec: &FormatSpec) -> Result { + fn fmt(&self, f: Writer, spec: &FormatSpec) -> FmtResult { ScoreDebug::fmt(&**self, f, spec) } } impl ScoreDebug for std::sync::Arc { - fn fmt(&self, f: Writer, spec: &FormatSpec) -> Result { + fn fmt(&self, f: Writer, spec: &FormatSpec) -> FmtResult { ScoreDebug::fmt(&**self, f, spec) } } impl ScoreDebug for Option { - fn fmt(&self, f: Writer, spec: &FormatSpec) -> Result { + fn fmt(&self, f: Writer, spec: &FormatSpec) -> FmtResult { match self { Some(v) => { let outer_spec = FormatSpec::new(); @@ -177,8 +177,27 @@ impl ScoreDebug for Option { } } +impl ScoreDebug for Result { + fn fmt(&self, f: Writer, spec: &FormatSpec) -> FmtResult { + match self { + Ok(v) => { + let outer_spec = FormatSpec::new(); + f.write_str("Ok(", &outer_spec)?; + ScoreDebug::fmt(v, f, spec)?; + f.write_str(")", &outer_spec) + }, + Err(e) => { + let outer_spec = FormatSpec::new(); + f.write_str("Err(", &outer_spec)?; + ScoreDebug::fmt(e, f, spec)?; + f.write_str(")", &outer_spec) + }, + } + } +} + impl ScoreDebug for Box { - fn fmt(&self, f: Writer, spec: &FormatSpec) -> Result { + fn fmt(&self, f: Writer, spec: &FormatSpec) -> FmtResult { ScoreDebug::fmt(&**self, f, spec) } } @@ -188,27 +207,27 @@ where K: ScoreDebug, V: ScoreDebug, { - fn fmt(&self, f: Writer, spec: &FormatSpec) -> Result { + fn fmt(&self, f: Writer, spec: &FormatSpec) -> FmtResult { let mut debug_map = DebugMap::new(f, spec); debug_map.entries(self.iter()).finish() } } impl ScoreDebug for std::sync::PoisonError { - fn fmt(&self, f: Writer, spec: &FormatSpec) -> Result { + fn fmt(&self, f: Writer, spec: &FormatSpec) -> FmtResult { let mut debug_struct = DebugStruct::new(f, spec, "PoisonError"); debug_struct.finish_non_exhaustive() } } impl ScoreDebug for (A, B) { - fn fmt(&self, f: Writer, spec: &FormatSpec) -> Result { + fn fmt(&self, f: Writer, spec: &FormatSpec) -> FmtResult { DebugTuple::new(f, spec, "").field(&self.0).field(&self.1).finish() } } impl ScoreDebug for (A, B, C) { - fn fmt(&self, f: Writer, spec: &FormatSpec) -> Result { + fn fmt(&self, f: Writer, spec: &FormatSpec) -> FmtResult { DebugTuple::new(f, spec, "") .field(&self.0) .field(&self.1) @@ -218,7 +237,7 @@ impl ScoreDebug for (A, B, C) { } impl ScoreDebug for (A, B, C, D) { - fn fmt(&self, f: Writer, spec: &FormatSpec) -> Result { + fn fmt(&self, f: Writer, spec: &FormatSpec) -> FmtResult { DebugTuple::new(f, spec, "") .field(&self.0) .field(&self.1) @@ -229,7 +248,7 @@ impl ScoreDebug for } impl ScoreDebug for (A, B, C, D, E) { - fn fmt(&self, f: Writer, spec: &FormatSpec) -> Result { + fn fmt(&self, f: Writer, spec: &FormatSpec) -> FmtResult { DebugTuple::new(f, spec, "") .field(&self.0) .field(&self.1) @@ -378,6 +397,14 @@ mod tests { common_test_debug(Option::::None); } + #[test] + fn test_result_debug() { + let r1: Result = Ok(123); + common_test_debug(r1); + let r2: Result = Err("fail"); + common_test_debug(r2); + } + #[test] fn test_box_debug() { common_test_debug(Box::new(432.1)); From 329bb6852e4455e6ae484583219c2f2455d25ebe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arkadiusz=20J=C4=99drzejewski?= Date: Fri, 27 Mar 2026 11:42:05 +0100 Subject: [PATCH 2/2] containers: make `score_log` obligatory - Remove gated features. - Remove `no_std` from containers. --- src/containers/Cargo.toml | 6 +----- src/containers/fixed_capacity/queue.rs | 15 +++++++-------- src/containers/fixed_capacity/string.rs | 18 ++++++++---------- src/containers/fixed_capacity/vec.rs | 15 +++++++-------- src/containers/generic/queue.rs | 8 ++++---- src/containers/generic/string.rs | 8 ++++---- src/containers/generic/vec.rs | 8 ++++---- src/containers/inline/option.rs | 10 +++++----- src/containers/inline/queue.rs | 10 ++++------ src/containers/inline/result.rs | 10 +++++----- src/containers/inline/string.rs | 8 ++++---- src/containers/inline/vec.rs | 10 ++++------ src/containers/lib.rs | 2 -- 13 files changed, 57 insertions(+), 71 deletions(-) diff --git a/src/containers/Cargo.toml b/src/containers/Cargo.toml index 8601bc69..82a468e2 100644 --- a/src/containers/Cargo.toml +++ b/src/containers/Cargo.toml @@ -24,8 +24,4 @@ path = "lib.rs" [dependencies] elementary.workspace = true -# `score_log` introduces `std`. -score_log = { workspace = true, optional = true } - -[features] -default = ["score_log"] +score_log.workspace = true diff --git a/src/containers/fixed_capacity/queue.rs b/src/containers/fixed_capacity/queue.rs index 9ada43e9..92a3a335 100644 --- a/src/containers/fixed_capacity/queue.rs +++ b/src/containers/fixed_capacity/queue.rs @@ -16,6 +16,7 @@ use crate::storage::Heap; use core::fmt; use core::ops; use elementary::{BasicAllocator, HeapAllocator, GLOBAL_ALLOCATOR}; +use score_log::fmt::{FormatSpec, Result as ScoreLogResult, ScoreDebug, Writer}; /// A fixed-capacity queue, using provided allocator. /// @@ -71,10 +72,9 @@ impl fmt::Debug for FixedCapacityQueueIn<'_, T } } -#[cfg(feature = "score_log")] -impl score_log::fmt::ScoreDebug for FixedCapacityQueueIn<'_, T, A> { - fn fmt(&self, f: score_log::fmt::Writer, spec: &score_log::fmt::FormatSpec) -> score_log::fmt::Result { - score_log::fmt::ScoreDebug::fmt(&self.inner, f, spec) +impl ScoreDebug for FixedCapacityQueueIn<'_, T, A> { + fn fmt(&self, f: Writer, spec: &FormatSpec) -> ScoreLogResult { + ScoreDebug::fmt(&self.inner, f, spec) } } @@ -115,10 +115,9 @@ impl fmt::Debug for FixedCapacityQueue { } } -#[cfg(feature = "score_log")] -impl score_log::fmt::ScoreDebug for FixedCapacityQueue { - fn fmt(&self, f: score_log::fmt::Writer, spec: &score_log::fmt::FormatSpec) -> score_log::fmt::Result { - score_log::fmt::ScoreDebug::fmt(&self.0, f, spec) +impl ScoreDebug for FixedCapacityQueue { + fn fmt(&self, f: Writer, spec: &FormatSpec) -> ScoreLogResult { + ScoreDebug::fmt(&self.0, f, spec) } } diff --git a/src/containers/fixed_capacity/string.rs b/src/containers/fixed_capacity/string.rs index de65abcc..2929763b 100644 --- a/src/containers/fixed_capacity/string.rs +++ b/src/containers/fixed_capacity/string.rs @@ -15,8 +15,8 @@ use crate::generic::string::GenericString; use crate::storage::Heap; use core::fmt; use core::ops; -use elementary::GLOBAL_ALLOCATOR; -use elementary::{BasicAllocator, HeapAllocator}; +use elementary::{BasicAllocator, HeapAllocator, GLOBAL_ALLOCATOR}; +use score_log::fmt::{FormatSpec, Result as ScoreLogResult, ScoreDebug, Writer}; /// A fixed-capacity Unicode string, using provided allocator.. /// @@ -98,10 +98,9 @@ impl fmt::Debug for FixedCapacityStringIn<'_, A> { } } -#[cfg(feature = "score_log")] -impl score_log::fmt::ScoreDebug for FixedCapacityStringIn<'_, A> { - fn fmt(&self, f: score_log::fmt::Writer, spec: &score_log::fmt::FormatSpec) -> score_log::fmt::Result { - score_log::fmt::ScoreDebug::fmt(self.as_str(), f, spec) +impl ScoreDebug for FixedCapacityStringIn<'_, A> { + fn fmt(&self, f: Writer, spec: &FormatSpec) -> ScoreLogResult { + ScoreDebug::fmt(self.as_str(), f, spec) } } @@ -161,10 +160,9 @@ impl fmt::Debug for FixedCapacityString { } } -#[cfg(feature = "score_log")] -impl score_log::fmt::ScoreDebug for FixedCapacityString { - fn fmt(&self, f: score_log::fmt::Writer, spec: &score_log::fmt::FormatSpec) -> score_log::fmt::Result { - score_log::fmt::ScoreDebug::fmt(&self.0, f, spec) +impl ScoreDebug for FixedCapacityString { + fn fmt(&self, f: Writer, spec: &FormatSpec) -> ScoreLogResult { + ScoreDebug::fmt(&self.0, f, spec) } } diff --git a/src/containers/fixed_capacity/vec.rs b/src/containers/fixed_capacity/vec.rs index c29eb5f6..09ee3790 100644 --- a/src/containers/fixed_capacity/vec.rs +++ b/src/containers/fixed_capacity/vec.rs @@ -16,6 +16,7 @@ use crate::storage::Heap; use core::fmt; use core::ops; use elementary::{BasicAllocator, HeapAllocator, GLOBAL_ALLOCATOR}; +use score_log::fmt::{FormatSpec, Result as ScoreLogResult, ScoreDebug, Writer}; /// A fixed-capacity vector, using provided allocator. /// @@ -85,10 +86,9 @@ impl fmt::Debug for FixedCapacityVecIn<'_, T, } } -#[cfg(feature = "score_log")] -impl score_log::fmt::ScoreDebug for FixedCapacityVecIn<'_, T, A> { - fn fmt(&self, f: score_log::fmt::Writer, spec: &score_log::fmt::FormatSpec) -> score_log::fmt::Result { - score_log::fmt::ScoreDebug::fmt(self.as_slice(), f, spec) +impl ScoreDebug for FixedCapacityVecIn<'_, T, A> { + fn fmt(&self, f: Writer, spec: &FormatSpec) -> ScoreLogResult { + ScoreDebug::fmt(self.as_slice(), f, spec) } } @@ -138,10 +138,9 @@ impl fmt::Debug for FixedCapacityVec { } } -#[cfg(feature = "score_log")] -impl score_log::fmt::ScoreDebug for FixedCapacityVec { - fn fmt(&self, f: score_log::fmt::Writer, spec: &score_log::fmt::FormatSpec) -> score_log::fmt::Result { - score_log::fmt::ScoreDebug::fmt(&self.0, f, spec) +impl ScoreDebug for FixedCapacityVec { + fn fmt(&self, f: Writer, spec: &FormatSpec) -> ScoreLogResult { + ScoreDebug::fmt(&self.0, f, spec) } } diff --git a/src/containers/generic/queue.rs b/src/containers/generic/queue.rs index 4bd8c7ea..24a184f0 100644 --- a/src/containers/generic/queue.rs +++ b/src/containers/generic/queue.rs @@ -18,6 +18,7 @@ use core::mem::needs_drop; use core::ops::Range; use core::ptr; use core::slice; +use score_log::fmt::{DebugList, FormatSpec, Result as ScoreLogResult, ScoreDebug, Writer}; use crate::storage::Storage; use crate::InsufficientCapacity; @@ -285,10 +286,9 @@ impl> fmt::Debug for GenericQueue { } } -#[cfg(feature = "score_log")] -impl> score_log::fmt::ScoreDebug for GenericQueue { - fn fmt(&self, f: score_log::fmt::Writer, spec: &score_log::fmt::FormatSpec) -> score_log::fmt::Result { - score_log::fmt::DebugList::new(f, spec).entries(self.iter()).finish() +impl> ScoreDebug for GenericQueue { + fn fmt(&self, f: Writer, spec: &FormatSpec) -> ScoreLogResult { + DebugList::new(f, spec).entries(self.iter()).finish() } } diff --git a/src/containers/generic/string.rs b/src/containers/generic/string.rs index 4e5e8bc0..e42f7bf1 100644 --- a/src/containers/generic/string.rs +++ b/src/containers/generic/string.rs @@ -14,6 +14,7 @@ use core::fmt; use core::ops; use core::str; +use score_log::fmt::{FormatSpec, Result as ScoreLogResult, ScoreDebug, Writer}; use super::vec::GenericVec; use crate::storage::Storage; @@ -137,10 +138,9 @@ impl> fmt::Debug for GenericString { } } -#[cfg(feature = "score_log")] -impl> score_log::fmt::ScoreDebug for GenericString { - fn fmt(&self, f: score_log::fmt::Writer, spec: &score_log::fmt::FormatSpec) -> score_log::fmt::Result { - score_log::fmt::ScoreDebug::fmt(self.as_str(), f, spec) +impl> ScoreDebug for GenericString { + fn fmt(&self, f: Writer, spec: &FormatSpec) -> ScoreLogResult { + ScoreDebug::fmt(self.as_str(), f, spec) } } diff --git a/src/containers/generic/vec.rs b/src/containers/generic/vec.rs index 743c1d01..2d915667 100644 --- a/src/containers/generic/vec.rs +++ b/src/containers/generic/vec.rs @@ -16,6 +16,7 @@ use core::marker::PhantomData; use core::mem::needs_drop; use core::ops; use core::ptr; +use score_log::fmt::{FormatSpec, Result as ScoreLogResult, ScoreDebug, Writer}; use crate::storage::Storage; use crate::InsufficientCapacity; @@ -175,10 +176,9 @@ impl> fmt::Debug for GenericVec { } } -#[cfg(feature = "score_log")] -impl> score_log::fmt::ScoreDebug for GenericVec { - fn fmt(&self, f: score_log::fmt::Writer, spec: &score_log::fmt::FormatSpec) -> score_log::fmt::Result { - score_log::fmt::ScoreDebug::fmt(self.as_slice(), f, spec) +impl> ScoreDebug for GenericVec { + fn fmt(&self, f: Writer, spec: &FormatSpec) -> ScoreLogResult { + ScoreDebug::fmt(self.as_slice(), f, spec) } } diff --git a/src/containers/inline/option.rs b/src/containers/inline/option.rs index afa01d96..ef9805e3 100644 --- a/src/containers/inline/option.rs +++ b/src/containers/inline/option.rs @@ -14,6 +14,7 @@ use core::cmp; use core::fmt; use core::mem::MaybeUninit; +use score_log::fmt::{FormatSpec, Result as ScoreLogResult, ScoreDebug, Writer}; /// An optional value, similar to [`Option`] in the Rust standard library. /// @@ -174,13 +175,12 @@ where } } -#[cfg(feature = "score_log")] -impl score_log::fmt::ScoreDebug for InlineOption +impl ScoreDebug for InlineOption where - for<'a> Option<&'a T>: score_log::fmt::ScoreDebug, + for<'a> Option<&'a T>: ScoreDebug, { - fn fmt(&self, f: score_log::fmt::Writer, spec: &score_log::fmt::FormatSpec) -> score_log::fmt::Result { - score_log::fmt::ScoreDebug::fmt(&self.as_ref(), f, spec) + fn fmt(&self, f: Writer, spec: &FormatSpec) -> ScoreLogResult { + ScoreDebug::fmt(&self.as_ref(), f, spec) } } diff --git a/src/containers/inline/queue.rs b/src/containers/inline/queue.rs index 048ef948..ea934fda 100644 --- a/src/containers/inline/queue.rs +++ b/src/containers/inline/queue.rs @@ -13,6 +13,7 @@ use core::fmt; use core::ops; +use score_log::fmt::{FormatSpec, Result as ScoreLogResult, ScoreDebug, Writer}; use crate::generic::queue::GenericQueue; use crate::storage::Inline; @@ -80,12 +81,9 @@ impl fmt::Debug for InlineQueue score_log::fmt::ScoreDebug - for InlineQueue -{ - fn fmt(&self, f: score_log::fmt::Writer, spec: &score_log::fmt::FormatSpec) -> score_log::fmt::Result { - score_log::fmt::ScoreDebug::fmt(&self.inner, f, spec) +impl ScoreDebug for InlineQueue { + fn fmt(&self, f: Writer, spec: &FormatSpec) -> ScoreLogResult { + ScoreDebug::fmt(&self.inner, f, spec) } } diff --git a/src/containers/inline/result.rs b/src/containers/inline/result.rs index d4e32e2f..8506d6e7 100644 --- a/src/containers/inline/result.rs +++ b/src/containers/inline/result.rs @@ -14,6 +14,7 @@ use core::cmp; use core::fmt; use core::mem::ManuallyDrop; +use score_log::fmt::{FormatSpec, Result as ScoreLogResult, ScoreDebug, Writer}; /// An result value for error handling, similar to [`Result`] in the Rust standard library. /// @@ -188,13 +189,12 @@ where } } -#[cfg(feature = "score_log")] -impl score_log::fmt::ScoreDebug for InlineResult +impl ScoreDebug for InlineResult where - for<'a> Result<&'a T, &'a E>: score_log::fmt::ScoreDebug, + for<'a> Result<&'a T, &'a E>: ScoreDebug, { - fn fmt(&self, f: score_log::fmt::Writer, spec: &score_log::fmt::FormatSpec) -> score_log::fmt::Result { - score_log::fmt::ScoreDebug::fmt(&self.as_ref(), f, spec) + fn fmt(&self, f: Writer, spec: &FormatSpec) -> ScoreLogResult { + ScoreDebug::fmt(&self.as_ref(), f, spec) } } diff --git a/src/containers/inline/string.rs b/src/containers/inline/string.rs index df1bbe81..17308329 100644 --- a/src/containers/inline/string.rs +++ b/src/containers/inline/string.rs @@ -13,6 +13,7 @@ use core::fmt; use core::ops; +use score_log::fmt::{FormatSpec, Result as ScoreLogResult, ScoreDebug, Writer}; use crate::generic::string::GenericString; use crate::storage::Inline; @@ -81,10 +82,9 @@ impl fmt::Debug for InlineString { } } -#[cfg(feature = "score_log")] -impl score_log::fmt::ScoreDebug for InlineString { - fn fmt(&self, f: score_log::fmt::Writer, spec: &score_log::fmt::FormatSpec) -> score_log::fmt::Result { - score_log::fmt::ScoreDebug::fmt(self.as_str(), f, spec) +impl ScoreDebug for InlineString { + fn fmt(&self, f: Writer, spec: &FormatSpec) -> ScoreLogResult { + ScoreDebug::fmt(self.as_str(), f, spec) } } diff --git a/src/containers/inline/vec.rs b/src/containers/inline/vec.rs index c8481149..9f45364d 100644 --- a/src/containers/inline/vec.rs +++ b/src/containers/inline/vec.rs @@ -13,6 +13,7 @@ use core::fmt; use core::ops; +use score_log::fmt::{FormatSpec, Result as ScoreLogResult, ScoreDebug, Writer}; use crate::generic::vec::GenericVec; use crate::storage::Inline; @@ -79,12 +80,9 @@ impl fmt::Debug for InlineVec score_log::fmt::ScoreDebug - for InlineVec -{ - fn fmt(&self, f: score_log::fmt::Writer, spec: &score_log::fmt::FormatSpec) -> score_log::fmt::Result { - score_log::fmt::ScoreDebug::fmt(self.as_slice(), f, spec) +impl ScoreDebug for InlineVec { + fn fmt(&self, f: Writer, spec: &FormatSpec) -> ScoreLogResult { + ScoreDebug::fmt(self.as_slice(), f, spec) } } diff --git a/src/containers/lib.rs b/src/containers/lib.rs index 9b693385..5444c96a 100644 --- a/src/containers/lib.rs +++ b/src/containers/lib.rs @@ -11,8 +11,6 @@ // SPDX-License-Identifier: Apache-2.0 // ******************************************************************************* -#![cfg_attr(not(test), no_std)] - extern crate alloc; pub mod fixed_capacity;