In software engineering, the singleton pattern is a software design pattern that restricts the instantiation of a class to one object. Wikipedia: Singleton Pattern. But this has a few problems. It is a mutable global variable, and in Rust, these are always unsafe to interact with.
Yes, Rust has Garbage Collection, and a Fast One
lazy_static - rust singleton struct - Code Examples
Rust is getting more and more popular. Thus, a group of colleagues, including myself, evaluated it for half a day to build up our own opinion, if Rust is of strategic interest for us or not. The general conclusion was more or less in the line of: yeah, a nice new programming language, but without a full-grown ecosystem and without any garbage collection, it will be too cumbersome and unproductive for us in our projects. My gut feeling did not agree with the assessment regarding garbage collection. Thus, I did some more digging and testing and came up with my current conclusion: Rust does indeed garbage collection, but in a very clever way.
Code Review Stack Exchange is a question and answer site for peer programmer code reviews. It only takes a minute to sign up. I'm new to Rust and am learning by implementing my own version of cut.
In this section we'll cover how to implement a global, shared singleton. The embedded Rust book covered local, owned singletons which are pretty much unique to Rust. TODO resources team link "the embedded Rust book" to the singletons section when it's up. To illustrate this section we'll extend the logger we developed in the last section to support global logging. In the last section we created a log!