Passing a member of a struct to a method of the same struct in Rust
<p>I am now facing a borrowing problem in Rust, and I have an idea to solve it. But I think the way I found is not a good answer. So I am wondering if there is another way to solve it.</p>

<p>I use the following example code to describe my situation:</p>

<pre><code>struct S {
    val: u8
}

impl S {
    pub fn f1(&amp;mut self) {
        println!("F1");
        self.f2(self.val);
    }

    pub fn f2(&amp;mut self, input: u8) {
        println!("F2");

        // Do something with input
    }
}

fn main() {
    let mut s = S {
        val: 0
    };

    s.f1();
}
</code></pre>

<p>Structure <code>S</code> has a method, <code>f2</code>, which takes an additional argument <code>input</code> to do something. There is another method, <code>f1</code>, which calls <code>f2</code> with the <code>val</code> of structure <code>S</code>. Outsider may call either <code>f1</code> or <code>f2</code> for different use cases.</p>

<p>When I compiled the above code, I got the following error message:</p>

<pre><code>src\main.rs:9:17: 9:25 error: cannot use `self.val` because it was mutably borrowed [E0503]
src\main.rs:9         self.f2(self.val);
                              ^~~~~~~~
src\main.rs:9:9: 9:13 note: borrow of `*self` occurs here
src\main.rs:9         self.f2(self.val);
                      ^~~~
</code></pre>

<p>I roughly understand how borrowing works in Rust. So I know that I can solve the problem by changing the implementation of <code>f1</code> to:</p>

<pre><code>pub fn f1(&amp;mut self) {
    let v = self.val;
    println!("F1");
    self.f2(v);
}
</code></pre>

<p>However, I feel this solution a little bit redundant. I am wondering if there is a way to solve this problem <strong>without using extra variable binding</strong>.</p>