Skip to content

Call functions written in Rust - #23

Merged
nickyoung-github merged 1 commit into
masterfrom
feature/rust-functions
Nov 29, 2026
Merged

nickyoung-github merged 1 commit into
masterfrom
feature/rust-functions

Conversation

@nickyoung-github

Copy link
Copy Markdown
Owner

A plain function of Rust, of the generated structs, is called from Python as a @native_function: as one of C++ is.

  • dataclass_native::python::function(extension, "name", f) adds it to the extension, as nanobind's def does one of C++. It is of up to 8 arguments, each of which, and what it gives, is a type which a field may be of, converted as a field is.
  • It is in the extension which holds the classes, pkg._native, as a class of pyo3 is of the extension it is built in: so that is what its @native_function names.
  • A frozen class is taken as its struct, which is copied, or as a Shared or a Held of it, which is not. What is given is not copied.
  • A Result it gives is raised if it is an error: as a ValueError, if not an exception of pyo3's. An argument it cannot take is a TypeError, "incompatible function arguments", as nanobind's is.

The tests of functions which are run with the C++ extensions are now run with that of Rust too, against the same functions written in Rust (tests/rust/functions.rs). Those are declared as of schemas._functions, so the test's copy of the package has a _functions.py which gives those of _native as that. A new test declares functions of schemas._native itself.

Of what Rust is yet to do, this leaves msgpack, JSON and Arrow, the descriptors of fields, and an example built with maturin.

… function, as nanobind's def adds one of C++
@nickyoung-github
nickyoung-github merged commit d2ecc6f into master Nov 29, 2026
6 checks passed
@nickyoung-github
nickyoung-github deleted the feature/rust-functions branch November 29, 2026 20:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant