summaryrefslogtreecommitdiffstats
path: root/ffi-macros
diff options
context:
space:
mode:
authorJustus Winter <justus@sequoia-pgp.org>2019-01-29 16:47:37 +0100
committerJustus Winter <justus@sequoia-pgp.org>2019-01-29 17:41:26 +0100
commit558a684ce0a2aadd6bfa7a4cda19e8a6de062e1c (patch)
treee2ece4465ca69aba224b9c7676b2eff6f8a97bb3 /ffi-macros
parentca715fb46d371a49492c51f829ea61f6883782ab (diff)
openpgp-ffi: Derive Serialize.
Diffstat (limited to 'ffi-macros')
-rw-r--r--ffi-macros/src/lib.rs21
1 files changed, 21 insertions, 0 deletions
diff --git a/ffi-macros/src/lib.rs b/ffi-macros/src/lib.rs
index 9d486ba5..5e815c3f 100644
--- a/ffi-macros/src/lib.rs
+++ b/ffi-macros/src/lib.rs
@@ -234,6 +234,7 @@ fn derive_functions() -> &'static HashMap<&'static str, DeriveFn>
h.insert("Hash", derive_hash as DeriveFn);
h.insert("Display", derive_to_string as DeriveFn);
h.insert("Debug", derive_debug as DeriveFn);
+ h.insert("Serialize", derive_serialize as DeriveFn);
h
};
}
@@ -643,3 +644,23 @@ fn derive_hash(span: proc_macro2::Span, prefix: &str, name: &str,
}
}
}
+
+/// Derives prefix_name_serialize.
+fn derive_serialize(span: proc_macro2::Span, prefix: &str, name: &str,
+ wrapper: &syn::Ident, _wrapped: &syn::Type)
+ -> TokenStream2
+{
+ let ident = syn::Ident::new(&format!("{}{}_serialize", prefix, name),
+ span);
+ quote! {
+ /// Serializes this object.
+ #[::ffi_catch_abort] #[no_mangle] pub extern "system"
+ fn #ident (errp: Option<&mut *mut ::error::Error>,
+ tsk: *const #wrapper,
+ writer: *mut Box<Write>)
+ -> Status {
+ let writer = ffi_param_ref_mut!(writer);
+ tsk.ref_raw().serialize(writer).move_into_raw(errp)
+ }
+ }
+}