/rustlings/blob/master/borrow.rs
Madhu
From: hata...@gmail.com
Date: Sat, 1 Jun 2013 22:30:35 -0700
To: abhijeet.ga...@gmail.com
CC: rust-dev@mozilla.org
Subject: Re: [rust-dev] Mutability and borrowing
True. I suppose I meant generic and memory efficient at the same time. I guess
it shouldn't be too
On Sun, Jun 2, 2013 at 12:33 AM, Ziad Hatahet hata...@gmail.com wrote:
I have the following function:
fn add_equal(x: mut Complex, y: Complex) {
x.real += y.real;
x.imag += y.imag;
}
Calling the function with the same variable being passed to both arguments
(i.e. add_equal(mut c,
On Sun, Jun 2, 2013 at 6:56 AM, Daniel Micay danielmi...@gmail.com wrote:
You can currently use `const Complex` for the second parameter, but
it may or may not be removed in the future. At the very least it will
probably be renamed.
Excellent. Thanks all for your replies :)
--
Ziad
I have the following function:
fn add_equal(x: mut Complex, y: Complex) {
x.real += y.real;
x.imag += y.imag;
}
Calling the function with the same variable being passed to both arguments
(i.e. add_equal(mut c, c)), results in the compile error:
error: cannot borrow `c` as immutable
Trying to concurrently borrow a value twice is never going to work.
You could write a function like double for such a situation.
--
Abhijeet Gaiha
http://about.me/abhijeet.gaiha
On Sunday, 2 June 2013 at 10:03 AM, Ziad Hatahet wrote:
I have the following function:
fn add_equal(x: mut
On Sat, Jun 1, 2013 at 9:33 PM, Ziad Hatahet hata...@gmail.com wrote:
I have the following function:
fn add_equal(x: mut Complex, y: Complex) {
x.real += y.real;
x.imag += y.imag;
}
Calling the function with the same variable being passed to both arguments
(i.e. add_equal(mut c,
Thanks everyone. I actually thought about the two suggestions before
posting. I thought there might be some common paradigm for this in the
language though.
So I take it that implementing a += operator overload function would not
have a generic way to handle the case where the same parameter is