GitHub PushEvent at 2014-03-26 03:26:55
Repository: rust
Actor: bors
Payload: {"shas":[["6200e761f0ef58510ad2acc383b29de7e7a79bcd","6a849a64ef95779be695d22e7034840fc522b96d@gmail.com","Changed `iter::Extendable` and `iter::FromIterator` to take a `Iterator` by value","Marvin Löbel",true],["34ffdeda154a1aee5fa5eec0ac3c9d643028361d","3a2c29237f73c7cf88424b80e427b1884f346b35@rust-lang.org","auto merge of #13039 : Kimundi/rust/iter_by_value_extend, r=alexcrichton\n\n# Summary \r\nChanged `iter::Extendable` and `iter::FromIterator` to take a `Iterator` by value.\r\nThese functions always exhaust the passed `Iterator`, and are often used for transferring the values of a new `Iterator` directly into a data structure, so using them usually require the use of the `&mut` operator:\r\n\r\n```\r\nfoo.extend(&mut bar.move_iter()); // Transfer content from bar into foo\r\n\r\nlet mut iter = ...;\r\nfoo.extend(&mut iter); // iter is now empty\r\n```\r\nThis patch changes both the `FromIterator` and `Extendable` traits to take the iterator by value instead, which makes the common case of using these traits less heavy:\r\n\r\n```\r\nfoo.extend(bar.move_iter()); // Transfer content from bar into foo\r\n\r\nlet iter = ...;\r\nfoo.extend(iter);\r\n// iter is now inaccessible if it moved\r\n// or unchanged if it was Pod and copied.\r\n```\r\n# Composability\r\nThis technically makes the traits less flexible from a type system pov, because they now require ownership. \r\n\r\nHowever, because `Iterator` provides the `ByRef` adapter, there is no loss of functionality:\r\n```\r\nfoo.extend(iter.by_ref()); // Same semantic as today, for the few situations where you need it.\r\n```\r\n\r\n# Motivation\r\nThis change makes it less painful to use iterators for shuffling values around between collections, which makes it more acceptable to always use them for this, enabling more flexibility.\r\n\r\nFor example, `foo.extend(bar.move_iter())` can generally be the fastest way to append an collections content to another one, without both needing to have the same type. Making this easy to use would allow the removal of special cased methods like `push_all()` on vectors. (See https://github.com/mozilla/rust/issues/12456)\r\n\r\nI opened https://github.com/mozilla/rust/issues/13038 as well, to discuss this change in general if people object to it.\r\n\r\n# Further work\r\nThis didn't change the `collect()` method to take by value `self`, nor any of the other adapters that also exhaust their iterator argument. For consistency this should probably happen in the long term, but for now this is too much trouble, as every use of them would need to be checked for accidentally changed semantic by going `&mut self -> self`. (which allows for the possibility that a `Pod` iterator got copied instead of exhausted without generating a type error by the change)","bors",true]],"size":2,"ref":"refs/heads/auto","head":"34ffdeda154a1aee5fa5eec0ac3c9d643028361d"}