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
/// _**`macros`**_ Define a newtype wrapper with a transparent representation
///
/// For `pub struct Wrapper(Inner)`:
///
/// - `Wrapper` implements `AsRepr<Inner>`
/// - `&Wrapper` implements `AsRepr<&Inner>`
/// - `&mut Wrapper` implements `AsRepr<&mut Inner>`
/// - `Pin<&Wrapper>` implements `AsRepr<Pin<&Inner>>`
/// - `Pin<&mut Wrapper>` implements `AsRepr<Pin<&mut Inner>>`
///
/// If the newtype is in a public API, and also has invariants that any access
/// to `Inner` must uphold, make sure the `Inner` type is either private or
/// inaccessible so consumers cannot invalidate the newtype's invariants.
///
/// # Example
///
/// ```rust
/// use std::fmt;
///
/// /// Wrapper type
/// as_repr::transparent_newtype! {
/// #[derive(Eq, PartialEq, Debug)]
/// pub struct Wrapper(i32);
/// }
///
/// impl fmt::Display for Wrapper {
/// fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
/// let inner: &i32 = as_repr::as_repr_ref(self);
///
/// write!(f, "{inner}")
/// }
/// }
///
/// assert_eq!(Wrapper(42).to_string(), "42");
/// ```
=> ;
}