In my opinion, there are two main reasons why one would prefer an immutable
API over a mutable one: aliasing and sharing substructures. Given that
unique pointers and references have mostly solved the first one, in my
opinion we should prefer mutable APIs unless the API is going to take
advantage
chain-oriented APIs (methods like `fn frob(self) - Frob`)
What about:
~~~
fn frob(self) - Frob {
let mut x = self;// not sure if you need `cast::transmute_mut` here
x.thing = foo();
x
}
~~~
That would solve the 'copying' problem.
I was actually considering doing this as a way
On Mon, Oct 21, 2013 at 4:10 PM, Brendan Zabarauskas bjz...@yahoo.com.auwrote:
chain-oriented APIs (methods like `fn frob(self) - Frob`)
What about:
~~~
fn frob(self) - Frob {
let mut x = self;// not sure if you need `cast::transmute_mut` here
x.thing = foo();
x
}
~~~
Date: Fri, 18 Oct 2013 10:54:23 -0700
From: Jeff Petkau j...@google.com
On my code (disclaimer: only toy projects to learn Rust so far), I've been
pretty happy with a mut_ prefix for mutable versions.
newthing = oldthing.push(foo)
anything.mut_push(foo)
x = bagofun.sort()
The new Path API still has a return a new path set of APIs. They're just
named differently. For example, the old path.push(foo) is now
path.join(foo). And all the path.set_*() mutating methods have variants
path.with_*() that return a new path.
-Kevin
On Oct 18, 2013, at 9:09 AM, Jack Moffitt
On Fri, Oct 18, 2013 at 12:09 PM, Jack Moffitt j...@metajack.im wrote:
In the latest Rust upgrade for Servo, I noticed that the path API is
now mutate-in-place instead of return a new path. It used to be that
path.push(foo) gave you a new path with an extra component, but now
path.push(foo)
On Oct 18, 2013, at 11:14 AM, Daniel Micay danielmi...@gmail.com wrote:
On Fri, Oct 18, 2013 at 12:09 PM, Jack Moffitt j...@metajack.im wrote:
In the latest Rust upgrade for Servo, I noticed that the path API is
now mutate-in-place instead of return a new path. It used to be that
On 10/18/2013 11:14 AM, Daniel Micay wrote:
On Fri, Oct 18, 2013 at 12:09 PM, Jack Moffitt j...@metajack.im
mailto:j...@metajack.im wrote:
In the latest Rust upgrade for Servo, I noticed that the path API is
now mutate-in-place instead of return a new path. It used to be that
On Fri, Oct 18, 2013 at 6:09 PM, Jack Moffitt j...@metajack.im wrote:
If we decide that both API styles are good to have, what should the
naming convention be for the functional vs. mutable ones? Ruby,
Scheme, and Clojure use `!` to denote the in-place mutation ones, but
that syntax is for
To be clear, '!' doesn't mean mutation, it means 'dangerous.' For example,
some methods return nil on error, and the bang version throws an excption
on error.
Sometimes, mutation is dangerous, though... ;)
___
Rust-dev mailing list
Rust-dev@mozilla.org
10 matches
Mail list logo