Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Format for the core::{iter, ops, slice} structs. #472

Merged
merged 3 commits into from
May 15, 2021
Merged
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
104 changes: 104 additions & 0 deletions src/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -488,3 +488,107 @@ where
Format::format(&(*self as *const T), fmt)
}
}

// core::ops

impl<Idx> Format for core::ops::Range<Idx>
where
Idx: Format,
{
fn format(&self, fmt: Formatter) {
defmt::write!(fmt, "{}..{}", self.start, self.end)
}
}

impl<Idx> Format for core::ops::RangeFrom<Idx>
where
Idx: Format,
{
fn format(&self, fmt: Formatter) {
defmt::write!(fmt, "{}..", self.start)
}
}

impl Format for core::ops::RangeFull {
fn format(&self, fmt: Formatter) {
defmt::write!(fmt, "..",)
}
}

impl<Idx> Format for core::ops::RangeInclusive<Idx>
where
Idx: Format,
{
fn format(&self, fmt: Formatter) {
defmt::write!(fmt, "{}..={}", self.start(), self.end())
}
}

impl<Idx> Format for core::ops::RangeTo<Idx>
where
Idx: Format,
{
fn format(&self, fmt: Formatter) {
defmt::write!(fmt, "..{}", self.end)
}
}

impl<Idx> Format for core::ops::RangeToInclusive<Idx>
where
Idx: Format,
{
fn format(&self, fmt: Formatter) {
defmt::write!(fmt, "..={}", self.end)
}
}

// core::iter

// Some of these objects don't expose enough to accurately report their debug state. In this case
// we show as much state as we can. Users can always use `Debug2Format` to get more information, at
// the cost of bringing core::fmt into the firmware and doing the layout work on device.

// keep the type parameter trait bounds in case it becomes possible use this later, without making
// a backwards-incompatible change.
impl<A, B> Format for core::iter::Zip<A, B>
where
A: Format,
B: Format,
{
fn format(&self, fmt: Formatter) {
defmt::write!(fmt, "Zip(..)")
}
}

// core::slice

impl<'a, T: 'a> Format for core::slice::ChunksExact<'a, T>
where
T: Format,
{
fn format(&self, fmt: Formatter) {
defmt::write!(fmt, "ChunksExact(..)")
}
}

impl<'a, T: 'a> Format for core::slice::Iter<'a, T>
where
T: Format,
{
fn format(&self, fmt: Formatter) {
defmt::write!(
fmt,
"Iter {{ slice: {=[?]}, position: ? }}",
self.as_slice()
)
}
}

impl<'a, T: 'a> Format for core::slice::Windows<'a, T>
where
T: Format,
{
fn format(&self, fmt: Formatter) {
defmt::write!(fmt, "Windows(..)")
}
}