diff options
author | Dj <43033058+DjDeveloperr@users.noreply.github.com> | 2023-01-07 19:58:10 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-08 09:28:10 +0530 |
commit | ad82918f56b215a428ebe7c533ee825e1152d1b4 (patch) | |
tree | 2669f9d8d419a88e9d58b12b98579e884aec6988 /ext/ffi/symbol.rs | |
parent | 84ef26ac9b5f0e1199d77837cd97cb203baa8729 (diff) |
feat(ext/ffi): structs by value (#15060)
Adds support for passing and returning structs as buffers to FFI. This does not implement fastapi support for structs. Needed for certain system APIs such as AppKit on macOS.
Diffstat (limited to 'ext/ffi/symbol.rs')
-rw-r--r-- | ext/ffi/symbol.rs | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/ext/ffi/symbol.rs b/ext/ffi/symbol.rs index 39466560b..bccef79b1 100644 --- a/ext/ffi/symbol.rs +++ b/ext/ffi/symbol.rs @@ -2,7 +2,7 @@ /// Defines the accepted types that can be used as /// parameters and return values in FFI. -#[derive(Clone, Copy, Debug, serde::Deserialize, Eq, PartialEq)] +#[derive(Clone, Debug, serde::Deserialize, Eq, PartialEq)] #[serde(rename_all = "lowercase")] pub enum NativeType { Void, @@ -22,6 +22,7 @@ pub enum NativeType { Pointer, Buffer, Function, + Struct(Box<[NativeType]>), } impl From<NativeType> for libffi::middle::Type { @@ -43,6 +44,9 @@ impl From<NativeType> for libffi::middle::Type { NativeType::Pointer | NativeType::Buffer | NativeType::Function => { libffi::middle::Type::pointer() } + NativeType::Struct(fields) => libffi::middle::Type::structure( + fields.iter().map(|field| field.clone().into()), + ), } } } |