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
/*!
Enum related traits and types.
The `*VariantField*` traits are declared in
[the `field` module](../field/index.html),
you can use `*VariantField*` traits as bounds,
and then call `StructuralExt` methods to access fields inside enum variants.
*/
pub use ;
use crateAssertTStrParam;
/// Queries whether an enum is some variant (the `V` type parameter)
///
/// Example bounds: `IsVariant<TS!(Foo)>`,`IsVariant<TS!(Bar)>`.
///
/// # Safety
///
/// An implementation of `IsVariant<TS!(Foo)>`
/// must only return true if the enum is the `Foo` variant
/// (`Foo` is just an example,it applies to all variants).
///
/// Undefined behavior will happen if this trait return `true`,
/// while the accessor for a field of that variant returns `None`.
///
///
/// # Example
///
/// ```rust
/// use structural::enums::IsVariant;
/// use structural::{TS,Structural,fp};
///
/// assertions(Enum::Foo, Enum::Bar(0), Enum::Boom{x:0,y:false});
///
/// assertions(Enum2::Foo, Enum2::Bar, Enum2::Boom);
///
/// fn assertions<T>(foo:T, bar:T, boom:T)
/// where
/// T: IsVariant<TS!(Foo)> + IsVariant<TS!(Bar)> + IsVariant<TS!(Boom)>
/// {
/// assert_eq!( foo.is_variant_(fp!(Foo)), true );
/// assert_eq!( foo.is_variant_(fp!(Bar)), false );
/// assert_eq!( foo.is_variant_(fp!(Boom)), false );
///
/// assert_eq!( bar.is_variant_(fp!(Foo)), false );
/// assert_eq!( bar.is_variant_(fp!(Bar)), true );
/// assert_eq!( bar.is_variant_(fp!(Boom)), false );
///
/// assert_eq!( boom.is_variant_(fp!(Foo)), false );
/// assert_eq!( boom.is_variant_(fp!(Bar)), false );
/// assert_eq!( boom.is_variant_(fp!(Boom)), true );
/// }
///
/// #[derive(Structural)]
/// # #[struc(no_trait)]
/// enum Enum{
/// Foo,
/// Bar(u8),
/// Boom{x:u32,y:bool},
/// }
///
/// #[derive(Structural)]
/// # #[struc(no_trait)]
/// enum Enum2{
/// Foo,
/// Bar,
/// Boom,
/// }
///
///
/// ```
pub unsafe