docs/rust/api_design.md
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 encapsulated and
not exposed to the user, and there isn’t an easy safe alternative.Chromium has three options available for interoperation with C and C++:
For more information, see ffi.md. In the long run, we prefer Crubit, but since it's not yet fully supported we use Cxx for now. Therefore, these guidelines aim to minimize the migration cost from Cxx to Crubit in the future.