mirror of
https://github.com/rust-lang-cn/book-cn.git
synced 2025-02-02 23:38:41 +08:00
We did see namespaces a bit, in ownership with String::from
This commit is contained in:
parent
507a668cb0
commit
c56d76de65
@ -74,12 +74,13 @@ f64::powi(2.0, 3)
|
||||
```
|
||||
|
||||
The double colon (`::`) here is a namespace operator. We haven’t talked about
|
||||
modules yet, but you can think of the `powi()` function as being scoped inside
|
||||
of another name. In this case, the name is `f64`, the same as the type. The
|
||||
`powi()` function takes two arguments: the first is a number, and the second is
|
||||
the power that it raises that number to. In this case, the second number is an
|
||||
integer, hence the ‘i’ in its name. Similarly, `sqrt()` is a function under the
|
||||
`f64` module, which takes the square root of its argument.
|
||||
modules and namespaces in depth yet, but you can think of the `powi()` function
|
||||
as being scoped inside of another name. In this case, the name is `f64`, the
|
||||
same as the type. The `powi()` function takes two arguments: the first is a
|
||||
number, and the second is the power that it raises that number to. In this
|
||||
case, the second number is an integer, hence the ‘i’ in its name. Similarly,
|
||||
`sqrt()` is a function under the `f64` module, which takes the square root of
|
||||
its argument.
|
||||
|
||||
## Why `struct`s?
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user