What does :: mean in Rust?

Please review Appendix B: Operators and Symbols of The Rust Programming Language.


In this case, the double colon (::) is the path separator. Paths are comprised of crates, modules, and items.

The full path for your example item, updated for 1.0 is:

std::usize::BITS

Here, std is the crate, usize is a module, and BITS is the specific item — in this case a constant.

If you scroll up in your file, you’ll see use core::usize. use adds the path to the set of items to look in. That’s how you can get away with just saying usize::BITS. The core crate is an implementation detail of the façade that is the std crate, so you can just substitute std for core in normal code.


:: can also be used as a way to specify generic types when they cannot otherwise be inferred; this is called the turbofish.

See also:

  • What is the syntax: `instance.method::<SomeThing>()`?

Leave a Comment

tech