revolt_models/
lib.rs

1#[cfg(feature = "serde")]
2#[macro_use]
3extern crate serde;
4
5#[cfg(feature = "schemas")]
6#[macro_use]
7extern crate schemars;
8
9#[cfg(feature = "utoipa")]
10#[macro_use]
11extern crate utoipa;
12
13#[cfg(feature = "partials")]
14#[macro_use]
15extern crate revolt_optional_struct;
16
17#[cfg(feature = "validator")]
18pub use validator;
19
20macro_rules! auto_derived {
21    ( $( $item:item )+ ) => {
22        $(
23            #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
24            #[cfg_attr(feature = "schemas", derive(JsonSchema))]
25            #[cfg_attr(feature = "utoipa", derive(ToSchema))]
26            #[derive(Debug, Clone, Eq, PartialEq)]
27            $item
28        )+
29    };
30}
31
32#[cfg(feature = "partials")]
33macro_rules! auto_derived_partial {
34    ( $item:item, $name:expr ) => {
35        #[derive(
36            OptionalStruct, Debug, Clone, Eq, PartialEq, Serialize, Deserialize, JsonSchema,
37        )]
38        #[optional_derive(
39            Debug,
40            Clone,
41            Eq,
42            PartialEq,
43            Serialize,
44            Deserialize,
45            JsonSchema,
46            Default
47        )]
48        #[optional_name = $name]
49        #[opt_skip_serializing_none]
50        #[opt_some_priority]
51        $item
52    };
53}
54
55#[cfg(not(feature = "partials"))]
56macro_rules! auto_derived_partial {
57    ( $item:item, $name:expr ) => {
58        #[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize, JsonSchema)]
59        $item
60    };
61}
62
63pub mod v0;
64
65/// Utility function to check if a boolean value is false
66pub fn if_false(t: &bool) -> bool {
67    !t
68}
69
70/// Utility function to check if an u32 is zero
71pub fn if_zero_u32(t: &u32) -> bool {
72    t == &0
73}
74
75/// Utility function to check if an option doesnt contain true
76pub fn if_option_false(t: &Option<bool>) -> bool {
77    t != &Some(true)
78}