Maybe this helps:
I tested it successfully but without rust-cython.
My way is creating a "cdylib" Target from Rust
Rust:
#[no_mangle] pub extern fn noise_texture_ds_middlefunc() -> fn(x1: f32, x2: f32, x3: f32, x4: f32) -> f32 { middle_quad } #[no_mangle] pub extern fn noise_texture_ds(width: i32, height: i32, maxred: f32, red: f32, startseed: f32, middlefunc: fn(x1: f32, x2: f32, x3: f32, x4: f32) -> f32) -> *mut u8 { ... }
pythonlib.py:
lib = ctypes.cdll.LoadLibrary("py_render_lib.dll") lib.noise_texture_ds.args = (c_int, c_int, c_float, c_float, c_float,) lib.noise_texture_ds.restype = POINTER(c_ubyte) lib.noise_texture_ds_middlefunc.restype = POINTER(CFUNCTYPE(c_float,c_float,c_float,c_float)) @CFUNCTYPE(c_float,c_float,c_float,c_float,c_float) def pymiddle(x1, x2, x3, x4): return (x1 + x2 + x3 + x4) / 2.5 def run_test(): print("start noise test") w = 513 #middlefunc = lib.noise_texture_ds_middlefunc() middlefunc = pymiddle result = lib.noise_texture_ds(c_int(w), c_int(w), c_float(1.0), c_float(0.5), c_float(1.0), middlefunc) .....
As you can see that works without any extra crate too.