const_format/
for_examples.rs

1//! Types for the documentation examples.
2//!
3//! # Features
4//!
5//! This module is only exported with the "fmt" feature
6
7use crate::{impl_fmt, try_, Error, Formatter, PWrapper};
8
9/// An example struct which implements const debug formatting.
10#[derive(Debug, Copy, Clone)]
11pub struct Point3 {
12    ///
13    pub x: u32,
14    ///
15    pub y: u32,
16    ///
17    pub z: u32,
18}
19
20impl_fmt! {
21    impl Point3;
22
23    ///
24    pub const fn const_debug_fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error> {
25        let mut f = f.debug_struct("Point3");
26        try_!(PWrapper(self.x).const_debug_fmt(f.field("x")));
27        try_!(PWrapper(self.y).const_debug_fmt(f.field("y")));
28        try_!(PWrapper(self.z).const_debug_fmt(f.field("z")));
29        f.finish()
30    }
31
32    ///
33    pub const fn const_eq(&self, other: &Self) -> bool {
34        self.x == other.x &&
35        self.y == other.y &&
36        self.z == other.z
37    }
38}
39
40/// An example unit struct which implements const debug formatting.
41#[derive(Debug, Copy, Clone)]
42pub struct Unit;
43
44impl_fmt! {
45    impl Unit;
46
47    ///
48    pub const fn const_debug_fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error> {
49        f.debug_struct("Unit").finish()
50    }
51
52    ///
53    pub const fn const_eq(&self, _other: &Self) -> bool {
54        true
55    }
56}