Skip to content
Discussion options

You must be logged in to vote

Generally you can accept anything which implements FromPyObject as an argument of a pyfunction. There are however only a limited number of types that can safely borrow from Python (&str, &[u8], Cow<str>, Cow<[u8]> and &T for T: PyClass). For &Path (any many other borrowing types) we can't provide a universal implementation, so you have to resort to the owned PathBuf. (We do provide the other direction, turning &Path into a Python object, which is probably the reason it is in the table.)

Duration should work just fine, assuming you take it by value:

#[pyfunction]
fn accept_duration(my_duration: std::time::Duration) -> PyResult<()> {
    todo!()
}

(This is basically a simpler version of wha…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@auspicacious
Comment options

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