Skip to content

How to use Vec<&str> as pyo3 struct field? #2128

Answered by birkenfeld
tushushu asked this question in Questions
Discussion options

You must be logged in to vote

What you could normally use in Rust for such cases is Vec<Rc<str>> which avoids the duplicates. I don't think this can be directly be exposed to Python though.

What about Vec<Py<PyString>>? If you have to expose the strings to Python, you'll have to convert them to PyString at some point anyway, and Py is like Rc in that you can clone them by just making a new reference. Python strings are also immutable.

Replies: 1 comment 5 replies

Comment options

You must be logged in to vote
5 replies
@tushushu
Comment options

@mejrs
Comment options

mejrs Jan 27, 2022
Collaborator

@tushushu
Comment options

@mejrs
Comment options

mejrs Jan 28, 2022
Collaborator

@tushushu
Comment options

Answer selected by tushushu
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants