Last active
August 6, 2020 21:23
-
-
Save tuzz/3e7795974757acb9f329ce16f36c4753 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[package] | |
name = "foo" | |
version = "0.1.0" | |
edition = "2018" | |
[dependencies] | |
legion = "0.2.4" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use legion::prelude::*; | |
use std::iter::once; | |
struct Foo; | |
fn main() { | |
let mut world = Universe::new().create_world(); | |
let entity = world.insert((), once((Foo,)))[0]; | |
if let Some(_foo) = world.get_component_mut::<Foo>(entity) { | |
} else { | |
world.add_component(entity, Foo).unwrap(); | |
} | |
} |
When the semi-colon is added, results in the following:
error[E0499]: cannot borrow `world` as mutable more than once at a time
--> src/main.rs:13:9
|
10 | if let Some(_foo) = world.get_component_mut::<Foo>(entity) {
| --------------------------------------
| |
| first mutable borrow occurs here
| a temporary with access to the first borrow is created here ...
...
13 | world.add_component(entity, Foo).unwrap();
| ^^^^^ second mutable borrow occurs here
14 | };
| - ... and the first borrow might be used here, when that temporary is dropped and runs the destructor for type `std::option::Option<legion::borrow::RefMut<'_, Foo>>`
error: aborting due to previous error
For more information about this error, try `rustc --explain E0499`.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Results in the following: