Skip to content

Share str.splitlines and bytes.splitlines implementaion #1883

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

Merged
merged 2 commits into from
Jul 22, 2020

Conversation

youknowone
Copy link
Member

No description provided.

Copy link
Contributor

@palaviv palaviv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's push this in and maybe later we will remove the duplication.


fn py_splitlines<U8, FW, W>(
&self,
bytes: impl std::iter::Iterator<Item = U8>,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, str::bytes() is std::iter::Itarator<Item=u8> but [u8]::iter() is std::iter::Iterator<Item=&u8>. Can I do this without CopyTo trait?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could probably just give it a byte slice using str.as_bytes()

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, it works. I am still curious how to write a generic function to take T and &T when T is a Copy. it is practically same but I couldn't find an easy way with std.

@youknowone youknowone merged commit 3f3a83c into RustPython:master Jul 22, 2020
@youknowone youknowone deleted the share-splitlines branch July 22, 2020 05:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants