1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#![no_std]
use core::fmt;
pub trait CustomFormat {
fn fmt(&self, f: &mut fmt::Formatter, spec: &str) -> fmt::Result;
}
pub struct CustomFormatter<'a, T> {
value: &'a T,
spec: &'static str,
}
impl<'a, T> CustomFormatter<'a, T> {
pub fn new(value: &'a T, spec: &'static str) -> Self {
Self { value, spec }
}
}
impl<T: CustomFormat> fmt::Display for CustomFormatter<'_, T> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
CustomFormat::fmt(self.value, f, self.spec)
}
}
pub use custom_format_macros::*;