How to transfer 'Py<PyAny>' to 'Bytes'? #3878
-
Currently, I got a return value from Here's the sample code:
|
Beta Was this translation helpful? Give feedback.
Answered by
davidhewitt
Feb 20, 2024
Replies: 1 comment 1 reply
-
At the moment we don't have first-party support for Also, in general I would recommend the following: let any: &PyAny = dump_fn.call(res, None)?;
let py_bytes: &PyBytes = any.downcast()?;
let bytes: Bytes = Bytes::copy_from_slice(py_bytes.as_bytes()); |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
k82cn
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
At the moment we don't have first-party support for
Bytes
(as per #1992), but that doesn't stop you from doing this conversion yourself viaBytes
constructors.Also, in general
Py<T>
is best for storing data and its counterpart&T
orBound<T>
(depending on pre/post 0.21) is easiest to work with for manipulating objects.I would recommend the following: