src/dolfinx_access/nanobind_helpers.cc

changeset 1
a4137aedcb3a
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/dolfinx_access/nanobind_helpers.cc	Thu Feb 26 09:32:12 2026 -0500
@@ -0,0 +1,29 @@
+/// Helpers to transmit nanobind C++ → Python bindings Python → Rust → C++.
+#include <Python.h>
+#include <nanobind/nanobind.h>
+
+#include "pointsource_pde/include/dolfinx_access/nanobind_helpers.h"
+
+using namespace nanobind;
+
+namespace dolfinx_access {
+    bool check_Function_f64(const PyObject* obj) {
+        auto handle = nanobind::handle(obj);
+        return nanobind::isinstance<Function_f64>(handle);
+    }
+
+    const Function_f64* cast_Function_f64(const PyObject* obj) {
+        auto handle = nanobind::handle(obj);
+        return nanobind::cast<const Function_f64*>(handle);
+    }
+
+    Function_f64* cast_mut_Function_f64(PyObject* obj) {
+        auto handle = nanobind::handle(obj);
+        return nanobind::cast<Function_f64*>(handle);
+    }
+
+    PyObject* wrap_Function_f64(Function_f64* f) {
+        return nanobind::cast(f).release().ptr();
+    }
+
+} // namespace dolfinx_access

mercurial