Hello!
I have done simple Resource Manager to load textures and accidentally I ran into issue.
Manager was just simple HashMap and something that can loads textures from hard drive into memory.
fn load(&mut self, details: String) -> Result<Rc<Texture<'l>>, String> {
//this doesn`t matter imo
result
}
But when i changed it into:
fn load(&mut self, details: String) -> <Rc<Texture<'l>>{
//this doesn`t matter imo
result.unwrap()
}
Then on second and third usage of function I got:
error[E0499]: cannot borrow `manager` as mutable more than once at a time
--> src/main.rs:115:20
|
113 | let texture = manager.load("animbg.png".to_string());
| ------- first mutable borrow occurs here
114 |
115 | let texture2 = manager.load("arrow.png".to_string());
| ^^^^^^^ second mutable borrow occurs here
...
347 | }
| - first borrow ends here
error[E0499]: cannot borrow `manager` as mutable more than once at a time
--> src/main.rs:117:20
|
113 | let texture = manager.load("animbg.png".to_string());
| ------- first mutable borrow occurs here
...
117 | let texture3 = manager.load("foo.png".to_string());
| ^^^^^^^ second mutable borrow occurs here
...
347 | }
| - first borrow ends here
error: aborting due to 2 previous errors
Line 347 is end of file of course.
fn load obviously needs mutable self since it is changing HashMap.
And this problem doesn`t appear if I just leave it as Result<_> and unwrap() at usage.
In my opinion it is at least very confisuing, does anybody know why is this happening?
I can of course put more code if needed. Anyway I mainly took SDL2 ResourceManager example.
Wowo