Rust Nibbles – Gazebo: The remainder of the tent

This article was written in collaboration with Neil Mitchell, a software engineer in the Developer Infrastructure organization at Facebook.

The Rust Gazebo Library contains a collection of proven Rust utilities in the form of stand-alone modules. In this series of blog posts, we’re going to cover some of the modules that make up the Gazebo Library. This blog is part of our Rust Nibbles series where we’ll go over the various Rust libraries we’ve made open source to learn more about what motivates their creation and how to use them.

Gazebo is a library of small functions, tested and documented so that they can be easily reused. Over the course of this series, we’ve explored some of the features Gazebo has to offer. But there are a number of others, some of which we will address in this post.

ARef: The ARef type represents a type that is either a Ref or a reference – e.g. Ref (borrowed from a RefCell) or & T (reference only). By hiding the distinction, we can work regardless of the real type.

TEq: The TEq type is a characteristic for similar types and can be used to combine two different types. For example, if a function needs two type parameters that should be the same, X: TEq makes sure that X and Y are actually of the same type, and x.teq () will do nothing and produce a value of type Y – to convince the compiler that the types are really the same.

PhantomDataInvariant: When you declare a PhantomData type T is considered covariant, so other types can be used instead. The PhantomDataInvariant type is invariant in terms of both type and lifetime, which ensures that it must exactly match the declarations.

Termination_on_Panic: The Terminate_on_Panic function does exactly that – as soon as a panic occurs, it ends the entire process. Most programs shouldn’t panic, but when they do, the last thing you want is for the panic to be accidentally swallowed. Ensuring immediate termination ensures that we don’t miss out on such cases.

Default_: When deriving a default instance for struct Foo(Opportunity), the default instance of Default requires that T itself be an instance of Default. In cases where T is within an option or Vec this is unnecessary. We permit #[derive(Default_)] to derive default without restrictions for type arguments. There are other packages that allow such types to be more accurately derived than what is / is not included, but this approach has proven to be a good standard.

We’re always on the lookout for new features to make writing Rust easier, so hopefully Gazebo’s features will grow over time.
We hope this blog helps you understand some of the remaining parts of Gazebo. With this we conclude our gazebo entries for the time being.

Check out our previous blogs in the Gazebo series to learn more about the various features the Gazebo Library has to offer –
Pavilion – Prelude
Pavilion – dupe
Pavilion variants
Pavilion – AnyLifetime
Pavilion – compare
Pavilion – conjures up and transforms

About the Rust Nibbles series

At Facebook, we believe that Rust is a stellar language that shines on critical issues like storage security, performance, and reliability. We have joined the Rust Foundation to contribute to the growth, advancement, and adoption of Rust, and the sustainable development of open source technologies and developer communities around the world.

This blog is part of our Rust Nibbles series where we’ll go over the various Rust libraries we’ve made open source to learn more about what motivates their creation and how to use them. We hope this series helps you create amazing projects 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.

Comments are closed.