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
//! Types for the documentation examples.
//!
//! # Features
//!
//! This module is only exported with the "fmt" feature, and the nightly compiler,
//! because at the time of writing these docs (2021-08-XX) mutable references in const fn
//! require the unstable
//! [`const_mut_refs`](https://github.com/rust-lang/rust/issues/57349) feature.
use crate::{impl_fmt, try_, Error, Formatter, PWrapper};
/// An example struct which implements const debug formatting.
#[derive(Debug, Copy, Clone)]
pub struct Point3 {
///
pub x: u32,
///
pub y: u32,
///
pub z: u32,
}
impl_fmt! {
impl Point3;
///
pub const fn const_debug_fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error> {
let mut f = f.debug_struct("Point3");
try_!(PWrapper(self.x).const_debug_fmt(f.field("x")));
try_!(PWrapper(self.y).const_debug_fmt(f.field("y")));
try_!(PWrapper(self.z).const_debug_fmt(f.field("z")));
f.finish()
}
///
pub const fn const_eq(&self, other: &Self) -> bool {
self.x == other.x &&
self.y == other.y &&
self.z == other.z
}
}
/// An example unit struct which implements const debug formatting.
#[derive(Debug, Copy, Clone)]
pub struct Unit;
impl_fmt! {
impl Unit;
///
pub const fn const_debug_fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error> {
f.debug_struct("Unit").finish()
}
///
pub const fn const_eq(&self, _other: &Self) -> bool {
true
}
}