This article was written in collaboration with Neil Mitchell, a Software Engineer in the Developer Infrastructure organization at Facebook.
The Rust library Gazebo contains a collection of well-tested Rust utilities in the form of standalone modules. In this series of blog posts, we will cover some of the modules that make up the Gazebo library. This blog is a part of our Rust Nibbles series, where we go over the various Rust libraries we have open-sourced to learn more about what motivated their creation and how one can use them.
Gazebo is a library of little functions, tested and documented, so they can be easily reused. In the course of this series, we’ve explored a few of the features that Gazebo has to offer. But there are a bunch of others left, some of which we touch upon in this post.
ARef: The ARef type represents a type that is either a Ref or a reference - e.g. Ref<T> (borrowed from a RefCell) or &T (just a reference). By hiding the distinction we can operate without regard for the real type.
TEq: The TEq type is a trait for types which are equal, and can be used to unify two distinct types. For example, if a function takes two type parameters you want to be equal, X : TEq<Y> will ensure that X and Y are actually the same type, and x.teq() will do nothing and produce a value of type Y - persuading the compiler that the types really are equal.
PhantomDataInvariant: If you declare a PhantomData<T> the type T is considered to be covariant, so other types can be used instead. The type PhantomDataInvariant is invariant in both the type and any lifetimes, ensuring it must precisely match what is declared.
terminate_on_panic: The function terminate_on_panic does exactly that - as soon as a panic occurs, it terminates the entire process. Most programs shouldn’t panic, but when they do, the last thing you want to happen is for the panic to be accidentally swallowed. Ensuring immediate termination makes sure we don’t miss such instances.
Default_: When deriving a Default instance for struct Foo<T>(Option<T>), the standard Default instance will require that T is itself an instance of Default. For cases where T is inside an Option or Vec, that is unnecessary. We allow #[derive(Default_)] to derive Default without any bounds on type arguments. There are other packages which allow deriving such types with more precision over what is/isn’t included, but this approach has turned out to be a good default.
We’re always looking to add new features that make writing Rust easier, so hopefully the features of Gazebo will grow over time.
We hope that this blog helps you understand some of the remaining bits of Gazebo. With that, we conclude our Gazebo entries for now.
Be sure to check out our previous blogs in the Gazebo series to learn more about the various features the Gazebo library has to offer -
Gazebo - Prelude
Gazebo - Dupe
Gazebo - Variants
Gazebo - AnyLifetime
Gazebo - Comparisons
Gazebo - Casts and transmute
We at Facebook believe that Rust is an outstanding language that shines in critical issues such as memory safety, performance and reliability. We joined the Rust Foundation to help contribute towards the growth, advancement and adoption of Rust, and towards sustainable development of open source technologies and developer communities across the world.
This blog is a part of our Rust Nibbles series, where we go over the various Rust libraries we have open-sourced to learn more about what motivated their creation and how one can use them. We hope that this series helps you create amazing projects by using these libraries and encourages you to try them out.
To learn more about Facebook Open Source, visit our open source site, subscribe to our YouTube channel, or follow us on Twitter and Facebook.