Expand description
使用 for 迭代一系列值。
in 之后的表达式必须实现 IntoIterator trait。
字面量示例:
for _ in 1..3 {}- 遍历排他范围直到但不包括 3.for _ in 1..=3 {}- 在一个包含范围内迭代直到并包括 3.
(了解有关 范围模式 的更多信息)
in 的另一个用途是使用关键字 pub。
它允许用户将项声明为仅在给定的作用域内可见。
字面量示例:
pub(in crate::outer_mod) fn outer_mod_visible_fn() {}- fn 在outer_mod中可见
从 2018 版开始,pub(in path) 的路径必须以 crate、self 或 super 开头。
2015 版还可以使用以 :: 开头的路径或 crate root 中的模块。
有关详细信息,请参见 Reference。