A few methods have slipped in that, as far as I can tell, are just to make method chaining more convenient. In particular, Vec.append_one is just a push that returns self afterwards. Rather than bloat up the API with lots of similar-but-subtly-different methods, I’d prefer if this pattern were generalized to something reusable.
Ruby has tap for exactly this, and tap could be implemented pretty easily in Rust, though it’s exceptionally verbose:
//Stolen from kimundi
trait Tap {
fn tap(mut self, f: |&mut Self|) -> Self {
f(&mut self);
self
}
}
impl<T> Tap for T {}
fn main () {
let v = vec![1u, 2, 3];
v.tap(|v| v.push(100)).tap(|v| v.push(1024));
}
(on play)
An actual special form like a .. or -> operator would probably be more friendly, although Mo’ Sigils Means Mo’ Problems.
Regardless, it would just be a trivial sugar for foo.bar(); foo, and usage would look like:
foo..push(1)..push(2)..push(3)
foo->push(1)->push(2)->push(3)
foo(╯°□°)╯︵push(1)(╯°□°)╯︵push(2)(╯°□°)╯︵push(3)