1#![warn(missing_docs, unreachable_pub)]
4
5use proc_macro::TokenStream;
11use quote::quote;
12use syn::DeriveInput;
13
14#[proc_macro_derive(SilentDisplay)]
17pub fn silent_display(source: TokenStream) -> TokenStream {
18 let ast: DeriveInput = syn::parse(source).expect("Incorrect macro input");
19 let name = &ast.ident;
20 let (impl_generics, type_generics, where_clause) = &ast.generics.split_for_impl();
21 let gen = quote! {
22 impl #impl_generics ::std::fmt::Display for #name #type_generics #where_clause {
24 fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
25 write!(f, "<elided secret for {}>", stringify!(#name))
26 }
27 }
28 };
29 gen.into()
30}
31
32#[proc_macro_derive(SilentDebug)]
33pub fn silent_debug(source: TokenStream) -> TokenStream {
36 let ast: DeriveInput = syn::parse(source).expect("Incorrect macro input");
37 let name = &ast.ident;
38 let (impl_generics, type_generics, where_clause) = &ast.generics.split_for_impl();
39 let gen = quote! {
40 impl #impl_generics ::std::fmt::Debug for #name #type_generics #where_clause {
42 fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
43 write!(f, "<elided secret for {}>", stringify!(#name))
44 }
45 }
46 };
47 gen.into()
48}
49
50#[proc_macro_derive(GroupOpsExtend)]
53pub fn group_ops(source: TokenStream) -> TokenStream {
54 let ast: DeriveInput = syn::parse(source).expect("Incorrect macro input");
55 let name = &ast.ident;
56
57 let gen = quote! {
58
59 auto_ops::impl_op!(+ |a: &#name, b: &#name| -> #name { <#name as core::ops::Add>::add(*a, *b) });
63 auto_ops::impl_op!(+ |a: &#name, b: #name| -> #name { <#name as core::ops::Add>::add(*a, b) });
64 auto_ops::impl_op!(+ |a: #name, b: &#name| -> #name { <#name as core::ops::Add>::add(a, *b) });
65
66 auto_ops::impl_op!(- |a: &#name, b: &#name| -> #name { <#name as core::ops::Sub>::sub(*a, *b) });
67 auto_ops::impl_op!(- |a: &#name, b: #name| -> #name { <#name as core::ops::Sub>::sub(*a, b) });
68 auto_ops::impl_op!(- |a: #name, b: &#name| -> #name { <#name as core::ops::Sub>::sub(a, *b) });
69
70 auto_ops::impl_op_ex!(+= |a: &mut #name, b: &#name| { *a = <#name as core::ops::Add>::add(*a, *b) });
71 auto_ops::impl_op_ex!(-= |a: &mut #name, b: &#name| { *a = <#name as core::ops::Sub>::sub(*a, *b) });
72 auto_ops::impl_op_ex!(*= |a: &mut #name, b: &<#name as GroupElement>::ScalarType| { *a = <#name as core::ops::Mul<<#name as GroupElement>::ScalarType>>::mul(*a, *b) });
73
74 auto_ops::impl_op!(* |a: &#name, b: &<#name as GroupElement>::ScalarType| -> #name { <#name as core::ops::Mul<<#name as GroupElement>::ScalarType>>::mul(*a, *b) });
75 auto_ops::impl_op!(* |a: &#name, b: <#name as GroupElement>::ScalarType| -> #name { <#name as core::ops::Mul<<#name as GroupElement>::ScalarType>>::mul(*a, b) });
76 auto_ops::impl_op!(* |a: #name, b: &<#name as GroupElement>::ScalarType| -> #name { <#name as core::ops::Mul<<#name as GroupElement>::ScalarType>>::mul(a, *b) });
77
78 auto_ops::impl_op!(- |a: &#name| -> #name { <#name as core::ops::Neg>::neg(*a) });
79 };
80 gen.into()
81}