summaryrefslogtreecommitdiffstats
path: root/ffi-macros/src
diff options
context:
space:
mode:
authorJustus Winter <justus@sequoia-pgp.org>2019-02-05 14:39:39 +0100
committerJustus Winter <justus@sequoia-pgp.org>2019-02-05 17:54:20 +0100
commit2d1f6bb425e14d34f7ad40f59022d5e0a34fb79e (patch)
tree7f1fa457bb64af70e677c45cd211af7404bd9e0d /ffi-macros/src
parent518162d959a10c334df874d4b9a2ace108a15320 (diff)
ffi-macros: Implement RefMutRaw for Maybe<T>.
Diffstat (limited to 'ffi-macros/src')
-rw-r--r--ffi-macros/src/lib.rs22
1 files changed, 22 insertions, 0 deletions
diff --git a/ffi-macros/src/lib.rs b/ffi-macros/src/lib.rs
index ad237238..ceb5d579 100644
--- a/ffi-macros/src/lib.rs
+++ b/ffi-macros/src/lib.rs
@@ -452,6 +452,28 @@ fn derive_conversion_functions(mut st: syn::ItemStruct,
}
}
+ impl RefMutRaw<Option<&'static mut #wrapped>> for ::Maybe<#wrapper> {
+ fn ref_mut_raw(self) -> Option<&'static mut #wrapped> {
+ if self.is_none() {
+ return None;
+ }
+ let wrapper = unsafe {
+ &mut (*self.unwrap().as_ptr())
+ };
+ wrapper.assert_tag();
+ match wrapper.0 {
+ #ownership::Owned(ref mut o) => Some(o),
+ #ownership::Ref(r) => {
+ panic!("FFI contract violation: expected mutable \
+ reference, got immutable reference: {:?}", r);
+ },
+ #ownership::RefMut(r) => unsafe {
+ Some(&mut *r)
+ },
+ }
+ }
+ }
+
impl #wrapper {
fn wrap(obj: #ownership) -> *mut #wrapper {
Box::into_raw(Box::new(#wrapper(obj, #magic_value,