Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion src/containers/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
1 change: 1 addition & 0 deletions src/containers/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@ path = "lib.rs"

[dependencies]
elementary.workspace = true
score_log.workspace = true
26 changes: 26 additions & 0 deletions src/containers/fixed_capacity/queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@

use crate::generic::queue::GenericQueue;
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.
///
Expand Down Expand Up @@ -64,6 +66,18 @@ impl<T, A: BasicAllocator> ops::DerefMut for FixedCapacityQueueIn<'_, T, A> {
}
}

impl<T: fmt::Debug, A: BasicAllocator> fmt::Debug for FixedCapacityQueueIn<'_, T, A> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt::Debug::fmt(&self.inner, f)
}
}

impl<T: ScoreDebug, A: BasicAllocator> ScoreDebug for FixedCapacityQueueIn<'_, T, A> {
fn fmt(&self, f: Writer, spec: &FormatSpec) -> ScoreLogResult {
ScoreDebug::fmt(&self.inner, f, spec)
}
}

/// A fixed-capacity queue, using global allocator.
/// Refer to [`FixedCapacityQueueIn`] for more information.
pub struct FixedCapacityQueue<T>(FixedCapacityQueueIn<'static, T, HeapAllocator>);
Expand Down Expand Up @@ -95,6 +109,18 @@ impl<T> ops::DerefMut for FixedCapacityQueue<T> {
}
}

impl<T: fmt::Debug> fmt::Debug for FixedCapacityQueue<T> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt::Debug::fmt(&self.0, f)
}
}

impl<T: ScoreDebug> ScoreDebug for FixedCapacityQueue<T> {
fn fmt(&self, f: Writer, spec: &FormatSpec) -> ScoreLogResult {
ScoreDebug::fmt(&self.0, f, spec)
}
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down
18 changes: 15 additions & 3 deletions src/containers/fixed_capacity/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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..
///
Expand Down Expand Up @@ -98,6 +98,12 @@ impl<A: BasicAllocator> fmt::Debug for FixedCapacityStringIn<'_, A> {
}
}

impl<A: BasicAllocator> ScoreDebug for FixedCapacityStringIn<'_, A> {
fn fmt(&self, f: Writer, spec: &FormatSpec) -> ScoreLogResult {
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>);
Expand Down Expand Up @@ -150,7 +156,13 @@ 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)
}
}

impl ScoreDebug for FixedCapacityString {
fn fmt(&self, f: Writer, spec: &FormatSpec) -> ScoreLogResult {
ScoreDebug::fmt(&self.0, f, spec)
}
}

Expand Down
13 changes: 13 additions & 0 deletions src/containers/fixed_capacity/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
///
Expand Down Expand Up @@ -85,6 +86,12 @@ impl<T: fmt::Debug, A: BasicAllocator> fmt::Debug for FixedCapacityVecIn<'_, T,
}
}

impl<T: ScoreDebug, A: BasicAllocator> ScoreDebug for FixedCapacityVecIn<'_, T, A> {
fn fmt(&self, f: Writer, spec: &FormatSpec) -> ScoreLogResult {
ScoreDebug::fmt(self.as_slice(), f, spec)
}
}

/// A fixed-capacity vector, using global allocator.
/// Refer to [`FixedCapacityVecIn`] for more information.
pub struct FixedCapacityVec<T>(FixedCapacityVecIn<'static, T, HeapAllocator>);
Expand Down Expand Up @@ -131,6 +138,12 @@ impl<T: fmt::Debug> fmt::Debug for FixedCapacityVec<T> {
}
}

impl<T: ScoreDebug> ScoreDebug for FixedCapacityVec<T> {
fn fmt(&self, f: Writer, spec: &FormatSpec) -> ScoreLogResult {
ScoreDebug::fmt(&self.0, f, spec)
}
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down
14 changes: 14 additions & 0 deletions src/containers/generic/queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@
// SPDX-License-Identifier: Apache-2.0
// *******************************************************************************

use core::fmt;
use core::iter::FusedIterator;
use core::marker::PhantomData;
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;
Expand Down Expand Up @@ -278,6 +280,18 @@ impl<T, S: Storage<T>> GenericQueue<T, S> {
}
}

impl<T: fmt::Debug, S: Storage<T>> fmt::Debug for GenericQueue<T, S> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_list().entries(self.iter()).finish()
}
}

impl<T: ScoreDebug, S: Storage<T>> ScoreDebug for GenericQueue<T, S> {
fn fmt(&self, f: Writer, spec: &FormatSpec) -> ScoreLogResult {
DebugList::new(f, spec).entries(self.iter()).finish()
}
}

pub struct Iter<'a, T> {
first: slice::Iter<'a, T>,
second: slice::Iter<'a, T>,
Expand Down
7 changes: 7 additions & 0 deletions src/containers/generic/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -137,6 +138,12 @@ impl<S: Storage<u8>> fmt::Debug for GenericString<S> {
}
}

impl<S: Storage<u8>> ScoreDebug for GenericString<S> {
fn fmt(&self, f: Writer, spec: &FormatSpec) -> ScoreLogResult {
ScoreDebug::fmt(self.as_str(), f, spec)
}
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down
7 changes: 7 additions & 0 deletions src/containers/generic/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -175,6 +176,12 @@ impl<T: fmt::Debug, S: Storage<T>> fmt::Debug for GenericVec<T, S> {
}
}

impl<T: ScoreDebug, S: Storage<T>> ScoreDebug for GenericVec<T, S> {
fn fmt(&self, f: Writer, spec: &FormatSpec) -> ScoreLogResult {
ScoreDebug::fmt(self.as_slice(), f, spec)
}
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down
10 changes: 10 additions & 0 deletions src/containers/inline/option.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
///
Expand Down Expand Up @@ -174,6 +175,15 @@ where
}
}

impl<T: Copy> ScoreDebug for InlineOption<T>
where
for<'a> Option<&'a T>: ScoreDebug,
{
fn fmt(&self, f: Writer, spec: &FormatSpec) -> ScoreLogResult {
ScoreDebug::fmt(&self.as_ref(), f, spec)
}
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down
14 changes: 14 additions & 0 deletions src/containers/inline/queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
// SPDX-License-Identifier: Apache-2.0
// *******************************************************************************

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;
Expand Down Expand Up @@ -73,6 +75,18 @@ impl<T: Copy, const CAPACITY: usize> ops::DerefMut for InlineQueue<T, CAPACITY>
}
}

impl<T: Copy + fmt::Debug, const CAPACITY: usize> fmt::Debug for InlineQueue<T, CAPACITY> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt::Debug::fmt(&self.inner, f)
}
}

impl<T: Copy + ScoreDebug, const CAPACITY: usize> ScoreDebug for InlineQueue<T, CAPACITY> {
fn fmt(&self, f: Writer, spec: &FormatSpec) -> ScoreLogResult {
ScoreDebug::fmt(&self.inner, f, spec)
}
}

#[cfg(test)]
mod tests {
use std::collections::VecDeque;
Expand Down
10 changes: 10 additions & 0 deletions src/containers/inline/result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
///
Expand Down Expand Up @@ -188,6 +189,15 @@ where
}
}

impl<T: Copy, E: Copy> ScoreDebug for InlineResult<T, E>
where
for<'a> Result<&'a T, &'a E>: ScoreDebug,
{
fn fmt(&self, f: Writer, spec: &FormatSpec) -> ScoreLogResult {
ScoreDebug::fmt(&self.as_ref(), f, spec)
}
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down
7 changes: 7 additions & 0 deletions src/containers/inline/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -81,6 +82,12 @@ impl<const CAPACITY: usize> fmt::Debug for InlineString<CAPACITY> {
}
}

impl<const CAPACITY: usize> ScoreDebug for InlineString<CAPACITY> {
fn fmt(&self, f: Writer, spec: &FormatSpec) -> ScoreLogResult {
ScoreDebug::fmt(self.as_str(), f, spec)
}
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down
7 changes: 7 additions & 0 deletions src/containers/inline/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -79,6 +80,12 @@ impl<T: Copy + fmt::Debug, const CAPACITY: usize> fmt::Debug for InlineVec<T, CA
}
}

impl<T: Copy + ScoreDebug, const CAPACITY: usize> ScoreDebug for InlineVec<T, CAPACITY> {
fn fmt(&self, f: Writer, spec: &FormatSpec) -> ScoreLogResult {
ScoreDebug::fmt(self.as_slice(), f, spec)
}
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down
2 changes: 0 additions & 2 deletions src/containers/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
// SPDX-License-Identifier: Apache-2.0
// *******************************************************************************

#![cfg_attr(not(test), no_std)]

extern crate alloc;

pub mod fixed_capacity;
Expand Down
Loading
Loading