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
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
//! 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.
//!
//! We generally keep the type parameter trait bounds in case it becomes possible to use this
//! later, without making a backwards-incompatible change.

mod alloc_;
mod array;
mod num;
mod ops;
mod slice;

use super::*;
use crate::export;

impl<T> Format for Option<T>
where
    T: Format,
{
    default_format!();

    #[inline]
    fn _format_tag() -> Str {
        internp!("None|Some({=?})")
    }

    #[inline]
    fn _format_data(&self) {
        match self {
            None => export::u8(&0),
            Some(x) => {
                export::u8(&1);
                export::istr(&T::_format_tag());
                x._format_data()
            }
        }
    }
}

impl<T, E> Format for Result<T, E>
where
    T: Format,
    E: Format,
{
    default_format!();

    #[inline]
    fn _format_tag() -> Str {
        internp!("Err({=?})|Ok({=?})")
    }

    #[inline]
    fn _format_data(&self) {
        match self {
            Err(e) => {
                export::u8(&0);
                export::istr(&E::_format_tag());
                e._format_data()
            }
            Ok(x) => {
                export::u8(&1);
                export::istr(&T::_format_tag());
                x._format_data()
            }
        }
    }
}

impl<T> Format for core::marker::PhantomData<T> {
    default_format!();

    #[inline]
    fn _format_tag() -> Str {
        internp!("PhantomData")
    }

    #[inline]
    fn _format_data(&self) {}
}

impl Format for core::convert::Infallible {
    default_format!();

    #[inline]
    fn _format_tag() -> Str {
        unreachable!();
    }

    #[inline]
    fn _format_data(&self) {
        unreachable!();
    }
}

impl Format for core::time::Duration {
    fn format(&self, fmt: Formatter) {
        crate::write!(
            fmt,
            "Duration {{ secs: {=u64}, nanos: {=u32} }}",
            self.as_secs(),
            self.subsec_nanos(),
        )
    }
}

impl<A, B> Format for core::iter::Zip<A, B>
where
    A: Format,
    B: Format,
{
    fn format(&self, fmt: Formatter) {
        crate::write!(fmt, "Zip(..)")
    }
}