Skip to content

Read, set and make objects bound to Rust without Python - #24

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

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

Conversation

@nickyoung-github

Copy link
Copy Markdown
Owner

The Rust extension now has the __fields__ and __maker__ which one of C++ has, in each of its modules: so a field is read and set, and an object made, by the extension itself. The Python runtime is unchanged, as it binds either alike.

  • The crate's Field is the descriptor, which the generated code gives what reads and writes the field of a struct. maker gives a class its __new__.
  • A type says how it is made as Python itself is to have it, and taken from that, with what the field is told: an enum by its members, a frozen struct by its class, and a tuple or a frozenset of what is as Python has it. The rest Python's converters do, as for C++: a container of enums, a Shared object, a union.
  • A frozen struct is Native by one implementation of the crate's, not one generated for each.
  • numpy's frombuffer is found once, not for each array which is read.

On an Apple M1, of extensions built for release, in nanoseconds:

C++ Rust, before Rust, now
Make Money(1.5, Currency.EUR) 300 904 431
Make a Trade, of 19 fields 3,568 6,705 4,006
Read a float 29 112 46
Read an enum 25 187 40
Read a nested object 153 312 169
Set an int 24 134 41
Set a nested object 58 235 107

The README's Performance section has these, with a column for Rust read and set by Python's descriptors, as it has for C++.

Tested as the descriptors of C++ are: by the tests which are for every mode, and by the same script of what a descriptor does, with the extension's own and with Python's in their place.

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

@nickyoung-github
nickyoung-github merged commit ef923a3 into master Nov 29, 2026
6 checks passed
@nickyoung-github
nickyoung-github deleted the feature/rust-descriptors branch November 29, 2026 21:00
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