educe/trait_handlers/ord/
mod.rs1mod models;
2mod ord_enum;
3mod ord_struct;
4mod panic;
5
6use quote::quote;
7use syn::{Data, DeriveInput, Meta};
8
9use super::TraitHandler;
10use crate::Trait;
11
12pub(crate) struct OrdHandler;
13
14impl TraitHandler for OrdHandler {
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 match ast.data {
23 Data::Struct(_) => {
24 ord_struct::OrdStructHandler::trait_meta_handler(ast, token_stream, traits, meta)
25 },
26 Data::Enum(_) => {
27 ord_enum::OrdEnumHandler::trait_meta_handler(ast, token_stream, traits, meta)
28 },
29 Data::Union(_) => {
30 Err(crate::panic::trait_not_support_union(meta.path().get_ident().unwrap()))
31 },
32 }
33 }
34}
35
36fn supertraits(#[allow(unused_variables)] traits: &[Trait]) -> Vec<proc_macro2::TokenStream> {
37 let mut supertraits = vec![];
38 supertraits.push(quote! {::core::cmp::Eq});
39
40 #[cfg(feature = "PartialOrd")]
44 if !traits.contains(&Trait::PartialOrd) {
45 supertraits.push(quote! {::core::cmp::PartialOrd});
46 };
47
48 supertraits
49}