parse_display/
helpers.rs
1use core::fmt;
2
3#[cfg(feature = "std")]
4pub use super::helpers_std::*;
5
6use crate::{DisplayFormat, FromStrFormat};
7
8pub struct Formatted<'a, T: ?Sized, F: DisplayFormat<T>> {
9 pub value: &'a T,
10 pub format: F,
11}
12impl<T: ?Sized, F: DisplayFormat<T>> fmt::Display for Formatted<'_, T, F> {
13 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
14 self.format.write(f, self.value)
15 }
16}
17
18pub fn parse_with<T, F>(fmt: F, s: &str) -> Result<T, F::Err>
19where
20 F: FromStrFormat<T>,
21{
22 fmt.parse(s)
23}
24
25pub struct FmtPointer<'a, T: ?Sized + fmt::Pointer>(pub &'a T);
26
27impl<'a, T: ?Sized + fmt::Pointer> fmt::Pointer for FmtPointer<'a, T> {
28 #[inline]
29 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
30 fmt::Pointer::fmt(self.0, f)
31 }
32}