Ask Lemmy
A Fediverse community for open-ended, thought provoking questions
Rules: (interactive)
1) Be nice and; have fun
Doxxing, trolling, sealioning, racism, and toxicity are not welcomed in AskLemmy. Remember what your mother said: if you can't say something nice, don't say anything at all. In addition, the site-wide Lemmy.world terms of service also apply here. Please familiarize yourself with them
2) All posts must end with a '?'
This is sort of like Jeopardy. Please phrase all post titles in the form of a proper question ending with ?
3) No spam
Please do not flood the community with nonsense. Actual suspected spammers will be banned on site. No astroturfing.
4) NSFW is okay, within reason
Just remember to tag posts with either a content warning or a [NSFW] tag. Overtly sexual posts are not allowed, please direct them to either [email protected] or [email protected].
NSFW comments should be restricted to posts tagged [NSFW].
5) This is not a support community.
It is not a place for 'how do I?', type questions.
If you have any questions regarding the site itself or would like to report a community, please direct them to Lemmy.world Support or email [email protected]. For other questions check our partnered communities list, or use the search function.
6) No US Politics.
Please don't post about current US Politics. If you need to do this, try [email protected] or [email protected]
Reminder: The terms of service apply here too.
Partnered Communities:
Logo design credit goes to: tubbadu
view the rest of the comments
Yes, you can have a
OnceLock<RWLock<T>>
which is something that will get initialized at some point, and then you can acquire a lock on it for either read or write. To use it you need to check and handle both conditions, so it's really secure.However if you're writing a single threaded application a global
let mut
should also be safe, but Rust doesn't know if your application is single-threaded, or even if it is, it might get imported by others that isn't. So you're forced to consider the safety of things that might not even be related to what you're doing. Which was my point, if you're writing a simple CLI single threaded app, the compiler blocking you from having a global variable seems pedantic and unnecessary, because it's forcing you to deal with the edge case of your app becoming multi-threaded in the future.Don't get me wrong, this is part of what makes Rust great, but it can be EXTREMELY pedantic.