3 ms·
this seems like a reasonable objection. for my part, i wish somebody would write a data modeling library for Python where the underlying objects are themselves
by ledauphin 4y ago
this seems like a reasonable objection.
for my part, i wish somebody would write a data modeling library for Python where the underlying objects are themselves Rust objects, such that they could be handed off to Rust code with no translation penalty, but where the data model definition happens completely on the Python side.
This would be helpful on larger teams where everyone needs to be able to contribute to the data model but not everyone is comfortable writing Rust.
- orf 4y agoIt's not possible to do with no translation penalty. Rust (and other languages like it) need the sizes of objects known at compile time in order to allocate space on the stack (and within struct fields). One way you could do it would be to add dynamically dispatched ".get_attribute(str) -> Option<...>" methods which adds a lot of overhead. Another way would be to have some bastardised `build.rs` script that constructs Rust structs from Python class definitions. This keeps the definitions in Python but obviously doesn't track dynamic changes to it at runtime.
- crabbone 4y agoAll Python objects are C structs already... that's in part why binding between Rust and Python is possible. Rust doesn't really have objects though. It has structs. But these are the definitions that exist ad definition time. They disappear into the ether at runtime, so, I'm not sure how such communication between Python and Rust could've happened. Or, in other words: did you mean communication at run time or at compile time? Does Python, in your version of events, generate Rust source code, or does it talk to a program written in Rust?