| 1 |
// defmt only works in ELF binaries, and using defmt makes Windows CI fail |
| 2 |
#![cfg(not(target_os = "windows"))] |
| 3 |
|
| 4 |
use defmt::Format; |
| 5 |
|
| 6 |
use crate::{CompactString, Drain, ReserveError, ToCompactStringError, Utf16Error}; |
| 7 |
|
| 8 |
impl Format for CompactString { |
| 9 |
fn format(&self, fmt: defmt::Formatter) { |
| 10 |
self.as_str().format(fmt) |
| 11 |
} |
| 12 |
} |
| 13 |
|
| 14 |
impl Format for Drain<'_> { |
| 15 |
fn format(&self, fmt: defmt::Formatter) { |
| 16 |
defmt::write!(fmt, "Drain({=str})", self.as_str()) |
| 17 |
} |
| 18 |
} |
| 19 |
|
| 20 |
impl Format for ToCompactStringError { |
| 21 |
fn format(&self, fmt: defmt::Formatter) { |
| 22 |
match self { |
| 23 |
ToCompactStringError::Reserve(reserve_error) => reserve_error.format(fmt), |
| 24 |
ToCompactStringError::Fmt(core::fmt::Error) => { |
| 25 |
defmt::write!(fmt, "Display::fmt() returned an error") |
| 26 |
} |
| 27 |
} |
| 28 |
} |
| 29 |
} |
| 30 |
|
| 31 |
impl Format for ReserveError { |
| 32 |
fn format(&self, fmt: defmt::Formatter) { |
| 33 |
defmt::write!(fmt, "Cannot allocate memory to hold CompactString") |
| 34 |
} |
| 35 |
} |
| 36 |
|
| 37 |
impl Format for Utf16Error { |
| 38 |
fn format(&self, fmt: defmt::Formatter) { |
| 39 |
defmt::write!(fmt, "invalid utf-16: lone surrogate found") |
| 40 |
} |
| 41 |
} |