What does the ::
syntax in Rust, as seen here, mean:
fn chunk(n: uint, idx: uint) -> uint {
let sh = uint::BITS - (SHIFT * (idx + 1));
(n >> sh) & MASK
}
In languages like Haskell it means a type hint, but here the compiler already has an annotation of that values type, so it seems it's likely type casting.
There are two things here. First is the `&` symbol which has similar meaning : (a reference to a variable) as in C/C++. The next symbol ` ' ` is actually not attached to the & symbol, but it is seen before a type followed by a single lower case letter in rust like ( &'a u32 ) or ( &'m Vec<f64>).
Rust has a feature called automatic referencing and dereferencing. Calling methods is one of the few places in Rust that has this behavior. Here’s how it works: when you call a method with object.something (), Rust automatically adds in &, &mut, or * so object matches the signature of the method.
What is rust? In steel component which is an alloy of Fe and minor elements for the purpose they serve. In service or actual use or while transporting, these steels may get corroded means Fe may get oxidized by ambient oxygen or moisture by electro-chemical reactions.
First is the `&` symbol which has similar meaning : (a reference to a variable) as in C/C++. The next symbol ` ' ` is actually not attached to the & symbol, but it is seen before a type followed by a single lower case letter in rust like ( &'a u32 ) or ( &'m Vec<f64>).
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:
Oops. I wasn't reading very clearly. In this case, it's just the normal way of referring to anything under a module. uint::BITS
is a constant, it seems.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With