-
Notifications
You must be signed in to change notification settings - Fork 777
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement PyClass for PathBuf and Path #1377
Comments
I'm trying to make a PR for this |
I think rather than |
I think it will be better to implement those three traits on OsStr and OsString, because that's what the this work is really about: converting between Python's magic strings and Rust's opaque OS strings. Path and PathBuf can just redirect to the implementations on OsStr and OsString. |
That sounds sensible to me! If you're looking at string types, it could be worth assessing if |
Should the conversion functions from/to OsStr/Cstr go onto the PyString struct? It would get four new methods:
The alternative would be to create new modules |
I would suggest avoiding new methods on Is there a reason the traits above don't provide enough functionality for what you need? The traits are all we need for |
I was just asking what you preferred, I'm fine with both. In any case, I wrote the trait implementations for OsStr/OsString: https://github.com/kangalioo/pyo3/blob/bbc578fda767134ff678c1ebc62eae5e0e756cb2/src/types/osstr.rs. I'd greatly appreciate if you could check it out to make sure I didn't do anything totally stupid. Comments with In the meantime, I'll be working on CStr/CString and Path/PathBuf. EDIT: Actually, I'm not gonna do the conversions for CStr/CString in this PR, since they're not really strings but byte arrays, so they don't fit with the rest of the PR. (And also because I don't see a big need to transfer C strings between Rust and Python and the work to support it doesn't seem to be worth it for me right now) |
👍 totally makes sense - nice work and thanks for the PR; I'll do my best to make time to review it as soon as I can. |
Closed by #1379 . Thanks again for the PR. |
There exists an infallible conversion from String to PathBuf (and hence Path), so if I'm not missing something, there is no real reason not to implement PyClass for PathBuf/Path.
That would allow Rust functions exposed to Python to take paths as parameters with the actual appropriate Rust type, instead of having to use String as a workaround.
The text was updated successfully, but these errors were encountered: