What the actual fuck is "Nutex"?
Nutex stands for NUllable muTEX. It's intended for the global states that cannot provide the value at the start of the app runtime and gives a convenient access to nullable value.
Why not just Mutex<Option<T>>?
You may use that, but it's very inconvenient.
For example, you created an app and you want to access and process the user client data stored in mutex in the some function that may be called only if user is logged in. With using the standard Tokio mutex you should unwrap the value all the time:
pub async
pub async
Double checking. Double headache.
But Nutex gives you this:
pub async
pub async
It simplifies the code a lot because Mutexes frequently
used with values that cannot be known at the time when
they are created.
And how I need to use the Nutex?
If you certainly know that value is not None, then you
can just lock the Nutex and access the value:
let nutex = from;
*nutex.lock.await = Stringfrom;
assert_eq!;
But if you're not sure that it's not None, prefer using Nutex::safe_lock:
if let Some = nutex.safe_lock.await
Other documentation about Nutex may be found in the tokio::sync::Mutex docs:
Nutex is just a wrapper for this anyway.