This policy lays out guidelines for designing the user-facing parts of core Rust libraries in Chromium. It is meant to provide guidance on relative priorities to help decide between different possible designs.
Note: These guidelines are aimed at core Rust libraries (e.g. //base) which expect to see broad, general use across Chromium. They may or may not apply to code designed for more specialized parts of the codebase. Conversely, since these guidelines are aimed at libraries in Chromium, they have different considerations than the Rust standard library, which aims to support all possible use cases.
These design principles are undergoing constant development; expect more to be added in the future. Existing guidelines should change only rarely.
The first of these goals is the most important; beyond that, these goals are not ordered.
unsafe code if at all possible.unsafe functions, as well as those that require unsafe in order to use the result (e.g. by returning a raw pointer).unsafe API, we should try to provide an equivalent safe API and encourage its use when possible.unsafe is acceptable, so long it is not exposed to the user, and there isn’t an easy safe alternative.