an-cabal / an-rope

an rope data structure
https://docs.rs/an-rope
MIT License
11 stars 2 forks source link

Rope should implement std::iter::Extend #14

Closed hawkw closed 7 years ago

hawkw commented 7 years ago

Rope should provide implementations of the std::iter::Extend trait, just like String.

We will want to implement Extend<char>, Extend<&'a char>, Extend<&'a str> and Extend<String>, just like String does. Should consider implementing Extend<Rope> as well?

hawkw commented 7 years ago

Okay @rachlmac, finishing these implementations should be pretty simple.

To get you started, the naïve solution for Extend<char> would just be to consume each character from the iterator one-by-one and add them to the end of the Rope. You could do that with a for ... in loop over the iterator.

You might get better performance out of collecting elements into a String and then just appending that onto the end of the Rope, as it would involve creating fewer intermediate ropes, and would only trigger one rebalance.

Implementing Extend<String> should be more or less the same, but with a couple types changed. We'll get to the implementation for borrowed references (&'a str and &'a char) tomorrow.