Command pattern in Rust
<p>I'm trying to implement a command line server application in Rust.
I'd like to have a list (or hash table) of commands that I can iterate over for printing usage and looking up/executing commands.</p>

<p>My problem is that each <code>Command</code> needs mutable references to the thing the command uses to execute (such as inserting a user into a database or something).  The borrow checker obviously doesn't like passing multiple mutable references around.  Is there a way to do this?  I started by having the <code>execute</code> method take in a reference to the things it needed but then I need a separate list for commands that need different things which sounds like it would get unwieldy.</p>

<p>Here's an example of the problem:</p>

<pre><code>struct SomeStruct {
    pub some_field: String,
}

impl SomeStruct {
    pub fn new(field: String) -&gt; SomeStruct {
        let some_struct = SomeStruct {
            some_field: field,
        };
        return some_struct;
    }

    pub fn change_field(&amp;mut self) {
        self.some_field = "Something else".to_string();
    }
}

struct SomeCommand&lt;'a&gt; {
    pub some_struct: &amp;'a mut SomeStruct,
}

impl&lt;'a&gt; SomeCommand&lt;'a&gt; {
    pub fn new(the_struct: &amp;'a mut SomeStruct) -&gt; SomeCommand {
        let some_command = SomeCommand {
            some_struct: the_struct,
        };
        return some_command;
    }

    pub fn execute(&amp;mut self) {
        self.some_struct.change_field();
    }
}

fn main() {
    let mut some_struct = SomeStruct::new("hey".to_string());
    let some_command1 = SomeCommand::new(&amp;mut some_struct);

    // Compiler complains because I'm making another mutable binding to some_struct
    let some_command2 = SomeCommand::new(&amp;mut some_struct);
}
</code></pre>

<p>Is there a better way to do this?</p>