Hello, Already 4 hours that I fight with Rust but nothing makes it, he always refuses to do what I want. If you can help me here is the code and the error:
response.header("Set-Cookie", "cookie1=test");
response.status(StatusCode::OK);
println!("{:?}",eq.method()); //GET
let mut ctn = ContentString::new(eq);
{
let mut test = |string| {
response.header("Set-Cookie", "cookie2=test");
println!("{}",string);
};
let mut tester = |string| {
response.header("Set-Cookie", "cookie3=test");
println!("{}",string);
};
test("test for error");
tester("second test off error");
}
ctn.echo("<html>");
ctn.echo("<head>");
ctn.echo("<title>Test WebSite</title>");
ctn.echo("</head>");
ctn.echo("<body>");
ctn.echo("<h1>test</h1>");
ctn.echo("</body>");
ctn.echo("</html>");
return response.body(Body::from(ctn.get().into_bytes())).unwrap();```
<pre><font color="#EF2929"><b>error[E0499]</b></font><b>: cannot borrow `response` as mutable more than once at a time</b>
<font color="#729FCF"><b>--> </b></font>src/main.rs:29:34
<font color="#729FCF"><b>|</b></font>
<font color="#729FCF"><b>25</b></font> <font color="#729FCF"><b>| </b></font> let mut test = |string| {
<font color="#729FCF"><b>| </b></font> <font color="#729FCF"><b>--------</b></font> <font color="#729FCF"><b>first mutable borrow occurs here</b></font>
<font color="#729FCF"><b>26</b></font> <font color="#729FCF"><b>| </b></font> response.header("Set-Cookie", "cookie2=test");
<font color="#729FCF"><b>| </b></font> <font color="#729FCF"><b>--------</b></font> <font color="#729FCF"><b>previous borrow occurs due to use of `response` in closure</b></font>
<font color="#729FCF"><b>...</b></font>
<font color="#729FCF"><b>29</b></font> <font color="#729FCF"><b>| </b></font> let mut tester = |string| {
<font color="#729FCF"><b>| </b></font> <font color="#EF2929"><b>^^^^^^^^</b></font> <font color="#EF2929"><b>second mutable borrow occurs here</b></font>
<font color="#729FCF"><b>30</b></font> <font color="#729FCF"><b>| </b></font> response.header("Set-Cookie", "cookie3=test");
<font color="#729FCF"><b>| </b></font> <font color="#729FCF"><b>--------</b></font> <font color="#729FCF"><b>borrow occurs due to use of `response` in closure</b></font>
<font color="#729FCF"><b>...</b></font>
<font color="#729FCF"><b>35</b></font> <font color="#729FCF"><b>| </b></font> }
<font color="#729FCF"><b>| </b></font> <font color="#729FCF"><b>-</b></font> <font color="#729FCF"><b>first borrow ends here</b></font>
<font color="#EF2929"><b>error</b></font><b>: aborting due to previous error</b>
<b>For more information about this error, try `rustc --explain E0499`.</b>
<font color="#EF2929"><b>error:</b></font> Could not compile `web`.
</pre>
Thank's for your response.