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
/// Helper functions for `repr(transparent)` types.
///
/// ## Safety
///
/// This is only safely implemented by `#[repr(transparent)]` wrapper types, and only if
/// [`ReprTransparent::Inner`] actually matches the inner type. It is recommended to use the
/// derive macro to implement this trait, as it prevents any accidental misuse.
///
/// ## Derive macro
///
/// If the `derive` feature is enabled, use the derive macro `derive(ReprTransparent)` to implement
/// this trait. The macro checks for the existence of the `repr(transparent)` attribute, sets
/// [`ReprTransparent::Inner`] to the inner type and implements [`ReprTransparent::into_inner`]
/// automatically, making the implementation refactoring-proof. Note that the derive macro expects
/// the singular non-zero-sized field to be the first one in the implementing type.
///
/// ## Remarks
///
/// An `as_transparent_mut_ref` method is not provided because the wrapper type might enforce
/// invariants that could be invalidated via a mutable reference to the inner type.
///
/// ## Example
///
/// ```rust
/// use bointer::ReprTransparent;
///
/// #[derive(ReprTransparent)]
/// #[repr(transparent)]
/// struct UsizeWrapper(usize);
///
/// let value = UsizeWrapper(42);
/// assert_eq!(value.into_inner(), 42usize);
///
/// let mut value = UsizeWrapper(42);
/// let reference: &usize = value.as_inner_ref();
/// assert_eq!(*reference, 42usize);
///
/// let mut_ptr: *mut usize = value.as_inner_mut_ptr();
/// unsafe { *mut_ptr = 43; }
/// assert_eq!(value.into_inner(), 43usize);
/// ```
pub unsafe