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
extern crate proc_macro;
use ;
/// Makes a "tagged bytes" struct with the given name you input.
///
/// * The struct is `repr(transparent)` over `[u8]`, making it one of those
/// nasty *dynamically sized* types.
/// * The inner field is `pub(crate)`. You can keep it private to your crate, or
/// if you want users to keep using the bytes as raw bytes you can impl
/// [Deref](core::ops::Deref) or make a method maybe.
/// * The macro creates some `pub(crate)` constructors with funny names:
/// `pub_crate_from_ref` and `pub_crate_from_mut`. The "secret" here is that
/// they must use [transmute](core::mem::transmute) to do their thing, but
/// since the code that does it is proc-macro generated then it won't fall
/// afoul of `forbid(unsafe_code)`. The strange names are selected so that
/// when necessary you can make `pub` methods using the common, or you can
/// make `try_` named methods that enforce any invariants of the type.
/// * If the `alloc` feature of this proc-macro crate is enabled, the output
/// will have an additional method named `pub_crate_from_box` which is keyed
/// to an `alloc` feature in your own crate, and which will require that
/// your crate have `extern crate alloc;` somewhere in the crate when its
/// `alloc` feature is enabled.
/// * The macro will also derive `PartialEq`, `Eq`, `PartialOrd`, `Ord`, and
/// `Hash`. The first two so that you get the `StructuralEq` impl, which a
/// type can only have when `PartialEq` and `Eq` are derived. Having
/// `StructuralEq` allows you to potentially use the type in a `match`
/// expression. The others are provided just in case you need them, and so
/// that the ordering and hash impls are sure to match the equality impls.
/// * Note that `Debug` is **not** derived. You'll have to decide how you want
/// to present the type for yourself.