ruma_macros/serde/
ord_as_ref_str.rs

1use proc_macro2::{Ident, TokenStream};
2use quote::quote;
3
4pub fn expand_partial_ord_as_ref_str(ident: &Ident) -> syn::Result<TokenStream> {
5    Ok(quote! {
6        #[automatically_derived]
7        #[allow(deprecated)]
8        impl ::std::cmp::PartialOrd for #ident {
9            fn partial_cmp(&self, other: &Self) -> ::std::option::Option<::std::cmp::Ordering> {
10                let other = ::std::convert::AsRef::<::std::primitive::str>::as_ref(other);
11                ::std::convert::AsRef::<::std::primitive::str>::as_ref(self).partial_cmp(other)
12            }
13        }
14    })
15}
16
17pub fn expand_ord_as_ref_str(ident: &Ident) -> syn::Result<TokenStream> {
18    Ok(quote! {
19        #[automatically_derived]
20        #[allow(deprecated)]
21        impl ::std::cmp::Ord for #ident {
22            fn cmp(&self, other: &Self) -> ::std::cmp::Ordering {
23                let other = ::std::convert::AsRef::<::std::primitive::str>::as_ref(other);
24                ::std::convert::AsRef::<::std::primitive::str>::as_ref(self).cmp(other)
25            }
26        }
27    })
28}