You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
error[E0515]: cannot return value referencing temporary value
--> src/main.rs:27:5
|
27 |CONFIG.lock().unwrap().get("1").unwrap()
| ----------------------^^^^^^^^^^^^^^^^^^
||| returns a value referencing data owned by the current function
| temporary value created here
error: aborting due to previous error
For more information about this error, try `rustc --explain E0515`.
error: could not compile `rustls-example`.
To learn more, run the command again with --verbose.
Process finished with exit code 101
The text was updated successfully, but these errors were encountered:
baoyachi
changed the title
how to get Mutex inner variable in once_cell
how to get Mutex inner variable in CONFIG in once_cell
Oct 19, 2020
That's not possible, because that would be unsfae.You are trying to return a pointer inside the value, protected by the mutex, but the pointer is not protected by a lock guard. That means that some other thread could sucesfully lock the mutext and mutate the protected data, invalidating the pointer. You need to either clone the data (using Arc<dyn IExt> would help) or use something like map from parking lot: https://docs.rs/lock_api/0.4.0/lock_api/struct.MutexGuard.html#method.map
how to get reference
Ext
inCONFIG
compile error:
The text was updated successfully, but these errors were encountered: