- Notifications
You must be signed in to change notification settings - Fork 897
Add FromPyObject impl for Cow<Path> & Cow<OsStr> #5497
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
Add FromPyObject impl for Cow<Path> & Cow<OsStr> #5497
Conversation
CodSpeed Performance ReportMerging #5497 will not alter performanceComparing Summary
|
178bd02 to b438e54 Compare
davidhewitt left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea, with possibly more to go 🤔
| if let Ok(s) = obj.extract::<&str>() { | ||
| return Ok(Cow::Borrowed(s.as_ref())); | ||
| } | ||
| | ||
| obj.extract::<OsString>().map(Cow::Owned) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Based on the above comment about &OsStr, I think we might be able to make this always not copy on unix platforms?
I'm unsure if this comment is correct. |
| Ah right, makes sense. Willing to delete that comment in this PR perhaps? Otherwise LGTM! |
b438e54 to 44b3311 Compare
davidhewitt left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually sorry quick suggestion for the tests.
src/conversions/std/osstr.rs Outdated
| } | ||
| | ||
| // Test extracting both valid UTF-8 and non-UTF-8 strings | ||
| test_extract(py, "Hello\0\n🐍"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually shall we assert here that this is the borrowed form as expected, and similar for the path tests?
Will need a cfg but not too bad.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No problem! Will add this to the test!
f9d1676 to 3f5e731 Compare 3f5e731 to cf72c95 Compare
Allow extracting a
PathandOsStrwithout copying when it is a valid utf8 string.