MCPcopy Create free account
hub / github.com/RustCrypto/utils / derive_zeroize_impl

Function derive_zeroize_impl

zeroize_derive/src/lib.rs:38–86  ·  view source on GitHub ↗
(input: DeriveInput)

Source from the content-addressed store, hash-verified

36}
37
38fn derive_zeroize_impl(input: DeriveInput) -> TokenStream {
39 let attributes = ZeroizeAttrs::parse(&input);
40
41 let mut generics = input.generics.clone();
42
43 let extra_bounds = match attributes.bound {
44 Some(bounds) => bounds.0,
45 None => attributes
46 .auto_params
47 .iter()
48 .map(|type_param| -> WherePredicate {
49 parse_quote! {#type_param: Zeroize}
50 })
51 .collect(),
52 };
53
54 generics.make_where_clause().predicates.extend(extra_bounds);
55
56 let ty_name = &input.ident;
57
58 let (impl_gen, type_gen, where_) = generics.split_for_impl();
59
60 let drop_impl = if attributes.drop {
61 quote! {
62 #[doc(hidden)]
63 impl #impl_gen Drop for #ty_name #type_gen #where_ {
64 fn drop(&mut self) {
65 self.zeroize()
66 }
67 }
68 }
69 } else {
70 quote! {}
71 };
72
73 let zeroizers = generate_fields(&input, quote! { zeroize });
74 let zeroize_impl = quote! {
75 impl #impl_gen ::zeroize::Zeroize for #ty_name #type_gen #where_ {
76 fn zeroize(&mut self) {
77 #zeroizers
78 }
79 }
80 };
81
82 quote! {
83 #zeroize_impl
84 #drop_impl
85 }
86}
87
88/// Derive the `ZeroizeOnDrop` trait.
89///

Callers 2

derive_zeroizeFunction · 0.85
parse_zeroize_testFunction · 0.85

Calls 3

generate_fieldsFunction · 0.85
mapMethod · 0.80
cloneMethod · 0.45

Tested by

no test coverage detected