Support for conversion between bytes and std::string #137
-
pybind11 supported automatic conversion between nanobind supports conversion from Some support for this was drafted in #23, but that was closed without merging, and the implementation and goals (if I understood them correctly) were a bit different than the approach used in #62. I'm unable to tell if the lack of automatic conversion in nanobind is an intentional design choice (users responsible for managing their own conversions) or if it simply hasn't been implemented yet (i.e., PR would be welcome). My interest would be that this works just like in pybind11 (no conversion of underlying string data / encoding), since this is a point of friction in migrating from pybind11 to nanobind. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
A correction to what you said: commit #62 introduced a wrapper type (see this page for details: https://nanobind.readthedocs.io/en/latest/exchanging.html). What you ask for is a type converter that automatically casts |
Beta Was this translation helpful? Give feedback.
A correction to what you said: commit #62 introduced a wrapper type (see this page for details: https://nanobind.readthedocs.io/en/latest/exchanging.html). What you ask for is a type converter that automatically casts
std::string
(or potentially,char *
-- same thing) intobytes
and vice versa. pybind11 really only supported this because of its Python 2.x heritage involving a mixture of byte and unicode-format strings. I don't actually think it's a good idea to do this anymore, and I am not eager to add support for it. My suggestion would be that you stay with pybind11, create a custom fork of nanobind, or adapt your own binding interface.