educe/trait_handlers/partial_ord/
mod.rs

1mod models;
2mod panic;
3mod partial_ord_enum;
4mod partial_ord_struct;
5
6use models::TypeAttributeBuilder;
7use syn::{Data, DeriveInput, Meta};
8
9use super::TraitHandler;
10use crate::Trait;
11
12pub(crate) struct PartialOrdHandler;
13
14impl TraitHandler for PartialOrdHandler {
15    #[inline]
16    fn trait_meta_handler(
17        ast: &DeriveInput,
18        token_stream: &mut proc_macro2::TokenStream,
19        traits: &[Trait],
20        meta: &Meta,
21    ) -> syn::Result<()> {
22        #[cfg(feature = "Ord")]
23        let contains_ord = traits.contains(&Trait::Ord);
24
25        #[cfg(not(feature = "Ord"))]
26        let contains_ord = false;
27
28        // if `contains_ord` is true, the implementation is handled by the `Ord` attribute
29        if contains_ord {
30            let _ = TypeAttributeBuilder {
31                enable_flag: true, enable_bound: false
32            }
33            .build_from_partial_ord_meta(meta)?;
34
35            // field attributes is also handled by the `Ord` attribute
36
37            Ok(())
38        } else {
39            match ast.data {
40                Data::Struct(_) => partial_ord_struct::PartialOrdStructHandler::trait_meta_handler(
41                    ast,
42                    token_stream,
43                    traits,
44                    meta,
45                ),
46                Data::Enum(_) => partial_ord_enum::PartialOrdEnumHandler::trait_meta_handler(
47                    ast,
48                    token_stream,
49                    traits,
50                    meta,
51                ),
52                Data::Union(_) => {
53                    Err(crate::panic::trait_not_support_union(meta.path().get_ident().unwrap()))
54                },
55            }
56        }
57    }
58}