What's the best way to set arguments in rust for List[str] #3189
-
Assume there is a python func: def string_func(codes: List[str] | None):
my_rust_func(codes) In rust side with pyo3, Thank you!! |
Beta Was this translation helpful? Give feedback.
Answered by
davidhewitt
May 29, 2023
Replies: 1 comment 2 replies
-
You also have
|
Beta Was this translation helpful? Give feedback.
2 replies
Answer selected by
sun-rs
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You also have
Option<&PyList>
. I would describe it like this:Option<&PyList>
does no type checking on the contents, so will be fastest argument to accept but you will have to accept performance cost and fallibility later when you get items from this list and need to check if they are strings.Option<Vec<&str>>
has checked all contents and placed them into a RustVec
. This is a much more expensive task than just accepting&PyList
, but you are now free to work with this data purely using Rust algorithms.Option<Vec<String>>
is the same but now you've also copied all the text data into newString
structures. This is more expensive again, but helpful if you need to keep ownership of the tex…