Here is a playground from OP's snippet which generates the following error message:
error[E0277]: `Rc<RefCell<Gui_Logger_Inner>>` cannot be shared between threads safely
--> src/lib.rs:51:1
|
51 | / lazy_static! {
52 | | static ref global_logger: Gui_Logger = Gui_Logger::new();
53 | | }
| |_^ `Rc<RefCell<Gui_Logger_Inner>>` cannot be shared between threads safely
|
= help: within `Gui_Logger`, the trait `Sync` is not implemented for `Rc<RefCell<Gui_Logger_Inner>>`
note: required because it appears within the type `Gui_Logger`
--> src/lib.rs:17:12
|
17 | pub struct Gui_Logger {
| ^^^^^^^^^^
note: required by a bound in `Lazy`
--> /playground/.cargo/registry/src/index.crates.io-6f17d22bba15001f/lazy_static-1.4.0/src/inline_lazy.rs:19:20
|
19 | pub struct Lazy<T: Sync>(Cell<Option<T>>, Once);
| ^^^^ required by this bound in `Lazy`
= note: this error originates in the macro `__lazy_static_create` which comes from the expansion of the macro `lazy_static` (in Nightly builds, run with -Z macro-backtrace for more info)
For more information about this error, try `rustc --explain E0277`.
error: could not compile `playground` (lib) due to previous error
The thread-safe version of Rc<RefCell<T>> is Arc<Mutex<T>>, so I'd try those types instead:
If a closure captures something that is not Send or Sync, it won't be Send or Sync either. Example. To make sure we don't allow such closures—which would break our thread-safe api—we need to add the Send + Sync trait bounds.
Pretty much, though I'd say the second statement is a little imprecise, or rather I wouldn't use the word infer here. The compiler automatically implementsSend and Sync for your type if it is composed entirely of Send and Sync types:
Send and Sync are also automatically derived traits. This means that, unlike every other trait, if a type is composed entirely of Send or Sync types, then it is Send or Sync. Almost all primitives are Send and Sync, and as a consequence pretty much all types you'll ever interact with are Send and Sync.
Send and Sync (and a few other traits) are known as auto traits because the compiler automatically implements them for your type if it is able to and unless you explicitlyopt out of that implementation.