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
//! Internal helpers to factor out the repetitive
//! [`Display`](std::fmt::Display) / [`LowerExp`](std::fmt::LowerExp) /
//! [`UpperExp`](std::fmt::UpperExp) triplet impls used across the coordinate
//! types in this crate.
//!
//! This module is `#[macro_use]`d from `lib.rs` so the macros are available
//! crate-wide. They are intentionally not exported (`#[macro_export]` is *not*
//! used) so they remain a private implementation detail.
//!
//! The single [`impl_quantity_fmt_triplet!`] macro emits the three trait
//! implementations from one declaration. The body is written *once*; the macro
//! supplies a per-impl alias (`use ::std::fmt::Display as $fmt_one;`, etc.)
//! so that the body can dispatch each per-quantity formatting call through the
//! correct trait.
//!
//! ## Shape
//!
//! ```ignore
//! impl_quantity_fmt_triplet! {
//! impl<C, F, U> for Position<C, F, U>
//! where { C: ReferenceCenter, F: ReferenceFrame, U: LengthUnit, },
//! fmt_each: { Quantity<U>, },
//! |this, f, FmtOne| {
//! write!(f, "...", ...)?;
//! FmtOne::fmt(&this.x(), f)?;
//! // ...
//! }
//! }
//! ```
//!
//! - `where { ... }` are the *common* bounds shared by all three impls. The
//! trailing comma is required (it is concatenated with the per-trait bound
//! list emitted by `fmt_each`).
//! - `fmt_each: { T1, T2, ... }` lists the types whose per-trait bound must be
//! added to each impl. For an impl of `Display` the macro appends
//! `T1: ::std::fmt::Display, T2: ::std::fmt::Display, ...`, and likewise for
//! `LowerExp` and `UpperExp`. Pass an empty list (`fmt_each: {},`) when the
//! formatted quantities already implement all three traits unconditionally.
//! - The closure-like `|this, f, FmtOne| { body }` captures the names used
//! inside the body for `&self`, the formatter, and the per-impl trait alias.