Re:Thoughts on Go vs. Rust vs. Zig
by spacechild1 on Friday December 05, 2025 @03:23PM
(#46166764)
I think a better example might be logging. How is this typically solved in Rust? Do you have to pass a Logger reference to every function that potentially wants to log something? (In C++ you would typically have functions/macros that operate on a global logger instance.)
[ Parent
| on HN ]
Re:Thoughts on Go vs. Rust vs. Zig
by whytevuhuni on Saturday December 06, 2025 @01:33PM
(#46175491)
In Rust you typically use the "log" crate, which also has a global logger instance [0]. There is also "tracing" which uses thread local storage.
As another comment said, global state is allowed. It just has to be proven thread-safe via Rust's Send and Sync traits, and 'static lifetime. I've used things like LazyLock and ArcSwap to achieve this in the past.