You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I would argue that since arrays in Rust have a fixed length, it would make more sense to convert this to a tuple, such that be Python class becomes
classExample:
inner: tuple[int, int, int]
I don't know if there are any technical limitations that go against this suggestion, but I think it would make sense to convert fixed-length sequence types to tuple.
Other thoughts/questions
Is there a way to manually specify how a Rust library type to a pyo3 type? Perhaps, something like this pseudo-code example is possible:
#[pyclass(get_all)]structExample{#[pyo3(type="tuple[int, int, int]")]// Maybe like this#[pyo3(type=pyo3::types::PyTuple)]// or like thisinner:[u32;3]
I couldn't find anything in the docs about how to do this in the docs, but if it's there please let me know! It would also help in cases where you dont want a [u8; N] to come out as bytes.
You could argue that the type of inner should be (u32, u32, u32), as according to the conversion table, this will map to a Python tuple. It will cause some longer type annotations of course (in my code base I have 3x3 matrices, typed as [[f32; 3]; 3], the alternative would be
With this simple
#[pyclass]
:the Python equivalent becomes
I would argue that since arrays in Rust have a fixed length, it would make more sense to convert this to a
tuple
, such that be Python class becomesI don't know if there are any technical limitations that go against this suggestion, but I think it would make sense to convert fixed-length sequence types to
tuple
.Other thoughts/questions
Is there a way to manually specify how a Rust library type to a pyo3 type? Perhaps, something like this pseudo-code example is possible:
I couldn't find anything in the docs about how to do this in the docs, but if it's there please let me know! It would also help in cases where you dont want a
[u8; N]
to come out asbytes
.You could argue that the type of
inner
should be(u32, u32, u32)
, as according to the conversion table, this will map to a Python tuple. It will cause some longer type annotations of course (in my code base I have 3x3 matrices, typed as[[f32; 3]; 3]
, the alternative would bebut I think this is OK. Don't know if there's a performance penalty to this.
The text was updated successfully, but these errors were encountered: