Skip to content

Share str.splitlines and bytes.splitlines implementaion#1883

Merged
youknowone merged 2 commits into
RustPython:masterfrom
youknowone:share-splitlines
Jul 22, 2020
Merged

Share str.splitlines and bytes.splitlines implementaion#1883
youknowone merged 2 commits into
RustPython:masterfrom
youknowone:share-splitlines

Conversation

@youknowone
Copy link
Copy Markdown
Member

No description provided.

Comment thread vm/src/obj/objstr.rs Outdated
Copy link
Copy Markdown
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.

Comment thread vm/src/obj/pystr.rs Outdated

fn py_splitlines<U8, FW, W>(
&self,
bytes: impl std::iter::Iterator<Item = U8>,
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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