-
Hi all! From what I understand in the docs it should work, however when I try to compile it I get the following: error[E0432]: unresolved import 'vec_of_str'
--> src\lib.rs:12:20
|
12 | m.add_function(wrap_pyfunction!(vec_of_str, m)?)?;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ no external crate 'vec_of_str'
|
= note: this error originates in the macro 'wrap_pyfunction' (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0277]: the trait bound 'Vec<&str>: PyFunctionArgument<'_, '_>' is not satisfied
--> src\lib.rs:5:31
|
5 | fn analyze_string(a: &str, b: Vec<&str>) -> PyResult<bool> {
| ^^^ the trait 'FromPyObject<'_>' is not implemented for 'Vec<&str>', which is required by 'Vec<&str>: PyFunctionArgument<'_, '_>'
|
= help: the trait 'FromPyObject<'_>' is implemented for 'Vec<T>'
= note: required for 'Vec<&str>' to implement 'FromPyObjectBound<'_, '_>'
= note: required for 'Vec<&str>' to implement 'PyFunctionArgument<'_, '_>'
note: required by a bound in 'extract_argument'
--> C:\Users\Ido\.cargo\registry\src\index.crates.io-6f17d22bba15001f\pyo3-0.23.3\src\impl_\extract_argument.rs:119:8
|
113 | pub fn extract_argument<'a, 'py, T>(
| ---------------- required by a bound in this function
...
119 | T: PyFunctionArgument<'a, 'py>,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in 'extract_argument' I am not sure how I should fix that, and since this seems like a basic primitive I thought it must have a good reason not to work out of the box. All documentation I find either tell me it should work or are from over 3 years which I suspect are not relevant yet. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Hi @IdoPort! Can you share the full code of your That said, I was able to modify your #[pyfunction]
fn analyze_string(a: &str, b: Vec<String>) -> PyResult<bool> {
Ok(false)
} and it now compiles. You might find the table of conversions between Python and Rust types useful. In this case, I'm not certain why we don't have an implementation of Depending on your use case, you might also be able to use either: use pyo3::types::PyString;
#[pyfunction]
fn analyze_string(a: &str, b: Vec<Bound<'_, PyString>>) -> PyResult<bool> {
Ok(false)
} or use pyo3::pybacked::PyBackedStr;
#[pyfunction]
fn analyze_string(a: &str, b: Vec<PyBackedStr>) -> PyResult<bool> {
Ok(false)
} but I'd try the |
Beta Was this translation helpful? Give feedback.
Hi @IdoPort!
Can you share the full code of your
src\lib.rs
file? That would make it easier to help you.That said, I was able to modify your
analyze_string
function to:and it now compiles. You might find the table of conversions between Python and Rust types useful. In this case, I'm not certain why we don't have an implementation of
FromPyObject
forVec<&str>
- perhaps there's some technical limitation that makes it difficult.Depending on your use case, you might also be able to use either: