aboutsummaryrefslogtreecommitdiff
path: root/rust/qemu-api/src/lib.rs
diff options
context:
space:
mode:
authorPaolo Bonzini <pbonzini@redhat.com>2024-11-30 17:26:24 +0100
committerPaolo Bonzini <pbonzini@redhat.com>2024-12-19 19:36:37 +0100
commite05fbacd20366de436db82b776dfbc77071f6e29 (patch)
treef44b694e66682a4e52ca565f1851cc1405bebcff /rust/qemu-api/src/lib.rs
parentba3b81f3b668d3faa6cbdb39e123394f7bf637c7 (diff)
downloadqemu-e05fbacd20366de436db82b776dfbc77071f6e29.zip
qemu-e05fbacd20366de436db82b776dfbc77071f6e29.tar.gz
qemu-e05fbacd20366de436db82b776dfbc77071f6e29.tar.bz2
rust: qemu-api: add a module to wrap functions and zero-sized closures
One recurring issue when writing Rust bindings is how to convert a Rust function ("fn" or "impl Fn") to a C function, and how to pass around "self" to a C function that only takes a void*. An easy solution would be to store on the heap a pair consisting of a pointer to the Rust function and the pointer to "self", but it is possible to do better. If an "Fn" has zero size (that is, if it is a zero-capture closures or a function pointer---which in turn includes all methods), it is possible to build a generic Rust function that calls it even if you only have the type; you don't need either the pointer to the function itself (because the address of the code is part of the type) or any closure data (because it has size zero). Introduce a wrapper that provides the functionality of calling the function given only its type. Reviewed-by: Zhao Liu <zhao1.liu@intel.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'rust/qemu-api/src/lib.rs')
-rw-r--r--rust/qemu-api/src/lib.rs1
1 files changed, 1 insertions, 0 deletions
diff --git a/rust/qemu-api/src/lib.rs b/rust/qemu-api/src/lib.rs
index 124bece..4b43e02 100644
--- a/rust/qemu-api/src/lib.rs
+++ b/rust/qemu-api/src/lib.rs
@@ -14,6 +14,7 @@ pub mod prelude;
pub mod bitops;
pub mod c_str;
+pub mod callbacks;
pub mod cell;
pub mod irq;
pub mod module;