Struct std::ops::Range1.0.0[][src]

pub struct Range<Idx> {
    pub start: Idx,
    pub end: Idx,
}
Expand description

(half-open) 范围包括在 (start..end) 之下和仅在 (start..end) 之上。

范围 start..end 包含 start <= x < end 的所有值。 如果为 start >= end,则为空。

Examples

start..end 语法是 Range:

assert_eq!((3..5), std::ops::Range { start: 3, end: 5 });
assert_eq!(3 + 4 + 5, (3..6).sum());
Run
let arr = [0, 1, 2, 3, 4];
assert_eq!(arr[ ..  ], [0, 1, 2, 3, 4]);
assert_eq!(arr[ .. 3], [0, 1, 2      ]);
assert_eq!(arr[ ..=3], [0, 1, 2, 3   ]);
assert_eq!(arr[1..  ], [   1, 2, 3, 4]);
assert_eq!(arr[1.. 3], [   1, 2      ]); // 这是 `Range`
assert_eq!(arr[1..=3], [   1, 2, 3   ]);
Run

Fields

start: Idx

(inclusive) 范围的下限。

end: Idx

范围 (exclusive) 的上限。

Implementations

如果范围中包含 item,则返回 true

Examples

assert!(!(3..5).contains(&2));
assert!( (3..5).contains(&3));
assert!( (3..5).contains(&4));
assert!(!(3..5).contains(&5));

assert!(!(3..3).contains(&3));
assert!(!(3..2).contains(&3));

assert!( (0.0..1.0).contains(&0.5));
assert!(!(0.0..1.0).contains(&f32::NAN));
assert!(!(0.0..f32::NAN).contains(&0.5));
assert!(!(f32::NAN..1.0).contains(&0.5));
Run

如果范围不包含任何项,则返回 true

Examples

assert!(!(3..5).is_empty());
assert!( (3..3).is_empty());
assert!( (3..2).is_empty());
Run

如果任何一方都无法比拟,则范围为空:

assert!(!(3.0..5.0).is_empty());
assert!( (3.0..f32::NAN).is_empty());
assert!( (f32::NAN..5.0).is_empty());
Run

Trait Implementations

返回值的副本。 Read more

source 执行复制分配。 Read more

使用给定的格式化程序格式化该值。 Read more

返回类型的 “default value”。 Read more

从迭代器的末尾删除并返回一个元素。 Read more

从迭代器的末尾返回第 n 个元素。 Read more

🔬 This is a nightly-only experimental API. (iter_advance_by #77404)

recently added

通过 n 元素从后向前推进迭代器。 Read more

这是 Iterator::try_fold() 的反向版本: 它从迭代器的后面开始接收元素。 Read more

一种迭代器方法,从后面开始,将迭代器的元素减少为单个最终值。 Read more

从后面搜索满足谓词的迭代器的元素。 Read more

返回迭代器的确切长度。 Read more

🔬 This is a nightly-only experimental API. (exact_size_is_empty #35428)

如果迭代器为空,则返回 trueRead more

返回迭代器的确切长度。 Read more

🔬 This is a nightly-only experimental API. (exact_size_is_empty #35428)

如果迭代器为空,则返回 trueRead more

返回迭代器的确切长度。 Read more

🔬 This is a nightly-only experimental API. (exact_size_is_empty #35428)

如果迭代器为空,则返回 trueRead more

返回迭代器的确切长度。 Read more

🔬 This is a nightly-only experimental API. (exact_size_is_empty #35428)

如果迭代器为空,则返回 trueRead more

返回迭代器的确切长度。 Read more

🔬 This is a nightly-only experimental API. (exact_size_is_empty #35428)

如果迭代器为空,则返回 trueRead more

返回迭代器的确切长度。 Read more

🔬 This is a nightly-only experimental API. (exact_size_is_empty #35428)

如果迭代器为空,则返回 trueRead more

返回迭代器的确切长度。 Read more

🔬 This is a nightly-only experimental API. (exact_size_is_empty #35428)

如果迭代器为空,则返回 trueRead more

返回迭代器的确切长度。 Read more

🔬 This is a nightly-only experimental API. (exact_size_is_empty #35428)

如果迭代器为空,则返回 trueRead more

将该值输入给定的 HasherRead more

将这种类型的切片送入给定的 Hasher 中。 Read more

索引后返回的类型。

执行索引 (container[index]) 操作。 Read more

执行可变索引 (container[index]) 操作。 Read more

被迭代的元素的类型。

推进迭代器并返回下一个值。 Read more

返回迭代器剩余长度的界限。 Read more

返回迭代器的第 n 个元素。 Read more

使用迭代器,返回最后一个元素。 Read more

返回迭代器的最小元素。 Read more

返回迭代器的最大元素。 Read more

使用迭代器,计算迭代次数并返回它。 Read more

🔬 This is a nightly-only experimental API. (iter_advance_by #77404)

recently added

通过 n 元素使迭代器前进。 Read more

创建一个从同一点开始的迭代器,但在每次迭代时以给定的数量逐步执行。 Read more

接受两个迭代器,并依次在两个迭代器上创建一个新的迭代器。 Read more

将两个迭代器压缩为成对的单个迭代器。 Read more

🔬 This is a nightly-only experimental API. (iter_intersperse #79524)

recently added

创建一个新的迭代器,该迭代器将 separator 的副本放置在原始迭代器的相邻项之间。 Read more

🔬 This is a nightly-only experimental API. (iter_intersperse #79524)

recently added

创建一个新的迭代器,该迭代器将 separator 生成的项放在原始迭代器的相邻项之间。 Read more

获取一个闭包并创建一个迭代器,该迭代器在每个元素上调用该闭包。 Read more

在迭代器的每个元素上调用一个闭包。 Read more

创建一个迭代器,该迭代器使用闭包确定是否应产生元素。 Read more

创建一个同时过滤和 maps 的迭代器。 Read more

创建一个迭代器,该迭代器给出当前迭代次数以及下一个值。 Read more

创建一个迭代器,它可以使用 peekpeek_mut 方法查看迭代器的下一个元素而不消耗它。有关更多信息,请参见他们的文档。 Read more

创建一个迭代器,该迭代器基于谓词 skip 个元素。 Read more

创建一个迭代器,该迭代器根据谓词产生元素。 Read more

🔬 This is a nightly-only experimental API. (iter_map_while #68537)

recently added

创建一个迭代器,该迭代器均基于谓词和 maps 产生元素。 Read more

创建一个跳过前 n 个元素的迭代器。 Read more

创建一个迭代器,它产生第一个 n 元素,如果底层迭代器提前结束,则产生更少的元素。 Read more

fold 相似的迭代器适配器,它保持内部状态并生成新的迭代器。 Read more

创建一个迭代器,其工作方式类似于 map,但是将嵌套的结构展平。 Read more

创建一个可简化嵌套结构体的迭代器。 Read more

创建一个迭代器,该迭代器在第一个 None 之后结束。 Read more

对迭代器的每个元素执行某些操作,将值传递给它。 Read more

借用一个迭代器,而不是使用它。 Read more

将迭代器转换为集合。 Read more

使用一个迭代器,从中创建两个集合。 Read more

🔬 This is a nightly-only experimental API. (iter_partition_in_place #62543)

new API

根据给定的谓词,对迭代器的元素进行就地重新排序,以使所有返回 true 的元素都在所有返回 false 的元素之前。 返回找到的 true 元素的数量。 Read more

🔬 This is a nightly-only experimental API. (iter_is_partitioned #62544)

new API

检查此迭代器的元素是否根据给定的谓词进行了分区,以便所有返回 true 的元素都在所有返回 false 的元素之前。 Read more

一个迭代器方法,它只要成功返回就应用函数,并产生单个最终值。 Read more

一个迭代器方法,该方法将一个容易犯错的函数应用于迭代器中的每个项,在第一个错误处停止并返回该错误。 Read more

通过应用操作将每个元素 fold 到一个累加器中,返回最终结果。 Read more

通过重复应用归约运算,将元素缩减为一个。 Read more

测试迭代器的每个元素是否与谓词匹配。 Read more

测试迭代器的任何元素是否与谓词匹配。 Read more

搜索满足谓词的迭代器的元素。 Read more

将函数应用于迭代器的元素,并返回第一个非无结果。 Read more

🔬 This is a nightly-only experimental API. (try_find #63178)

new API

将函数应用于迭代器的元素,并返回第一个真结果或第一个错误。 Read more

在迭代器中搜索元素,并返回其索引。 Read more

从右侧搜索迭代器中的元素,并返回其索引。 Read more

返回给出指定函数最大值的元素。 Read more

返回给出相对于指定比较函数的最大值的元素。 Read more

返回给出指定函数中最小值的元素。 Read more

返回给出相对于指定比较函数的最小值的元素。 Read more

反转迭代器的方向。 Read more

将成对的迭代器转换为一对容器。 Read more

创建一个迭代器,该迭代器将复制其所有元素。 Read more

创建一个迭代器,该迭代器将克隆所有元素。 Read more

不断重复的迭代器。 Read more

对迭代器的元素求和。 Read more

遍历整个迭代器,将所有元素相乘 Read more

Lexicographically 将此 Iterator 的元素与另一个元素进行比较。 Read more

🔬 This is a nightly-only experimental API. (iter_order_by #64295)

Lexicographically 就指定的比较函数而言,将此 Iterator 的元素与另一个元素进行比较。 Read more

Lexicographically 将此 Iterator 的元素与另一个元素进行比较。 Read more

🔬 This is a nightly-only experimental API. (iter_order_by #64295)

Lexicographically 就指定的比较函数而言,将此 Iterator 的元素与另一个元素进行比较。 Read more

确定此 Iterator 的元素是否与另一个元素相同。 Read more

🔬 This is a nightly-only experimental API. (iter_order_by #64295)

关于指定的相等函数,确定 Iterator 的元素是否与另一个元素相等。 Read more

确定此 Iterator 的元素是否与另一个元素不相等。 Read more

确定此 Iterator 的元素是否比另一个元素少 按字典顺序Read more

确定此 Iterator 的元素是否 按字典顺序 小于或等于另一个元素。 Read more

确定此 Iterator 的元素是否大于另一个元素的 按字典顺序Read more

确定此 Iterator 的元素是否 按字典顺序 大于或等于另一个元素。 Read more

🔬 This is a nightly-only experimental API. (is_sorted #53485)

new API

检查此迭代器的元素是否已排序。 Read more

🔬 This is a nightly-only experimental API. (is_sorted #53485)

new API

检查此迭代器的元素是否使用给定的比较器函数进行排序。 Read more

🔬 This is a nightly-only experimental API. (is_sorted #53485)

new API

检查此迭代器的元素是否使用给定的键提取函数进行排序。 Read more

此方法测试 selfother 值是否相等,并由 == 使用。 Read more

此方法测试 !=

开始索引绑定。 Read more

结束索引绑定。 Read more

如果范围中包含 item,则返回 trueRead more

开始索引绑定。 Read more

结束索引绑定。 Read more

如果范围中包含 item,则返回 trueRead more

方法返回的输出类型。

🔬 This is a nightly-only experimental API. (slice_index_methods)

如果在边界内,则返回此位置输出的共享引用。 Read more

🔬 This is a nightly-only experimental API. (slice_index_methods)

如果在边界内,则对此位置的输出返回一个可变引用。 Read more

🔬 This is a nightly-only experimental API. (slice_index_methods)

返回此位置输出的共享引用,而不执行任何边界检查。 即使未使用所得的引用,使用越界索引或悬空的 slice 指针调用此方法也是 [undefined 行为]Read more

🔬 This is a nightly-only experimental API. (slice_index_methods)

返回此位置输出的变量引用,而不执行任何边界检查。 即使未使用所得的引用,使用越界索引或悬空的 slice 指针调用此方法也是 [undefined 行为]Read more

🔬 This is a nightly-only experimental API. (slice_index_methods)

返回此位置输出的共享引用,如果越界则会触发 panic。 Read more

🔬 This is a nightly-only experimental API. (slice_index_methods)

返回此位置输出的变量引用,如果越界则会触发 panic。 Read more

使用语法 &self[begin .. end]&mut self[begin .. end] 实现子字符串切片。

从字节范围 [begin,end`) 返回给定字符串的片段。

此运算为 O(1)。

在 1.20.0 之前,IndexIndexMut 的直接实现仍支持这些索引操作。

Panics

如果 beginend 未指向字符的起始字节偏移量 (由 is_char_boundary 定义),begin > endend > len,则为 Panics。

Examples

let s = "Löwe 老虎 Léopard";
assert_eq!(&s[0 .. 1], "L");

assert_eq!(&s[1 .. 9], "öwe 老");

// 这些将是 panic:
// 字节 2 位于 `ö` 内:
// &s[2 ..3];

// byte 8 lies within `老` &s[1 ..
// 8];

// 字节 100 在字符串 &s[3 之外。
// 100];
Run

方法返回的输出类型。

🔬 This is a nightly-only experimental API. (slice_index_methods)

如果在边界内,则返回此位置输出的共享引用。 Read more

🔬 This is a nightly-only experimental API. (slice_index_methods)

如果在边界内,则对此位置的输出返回一个可变引用。 Read more

🔬 This is a nightly-only experimental API. (slice_index_methods)

返回此位置输出的共享引用,而不执行任何边界检查。 即使未使用所得的引用,使用越界索引或悬空的 slice 指针调用此方法也是 [undefined 行为]Read more

🔬 This is a nightly-only experimental API. (slice_index_methods)

返回此位置输出的变量引用,而不执行任何边界检查。 即使未使用所得的引用,使用越界索引或悬空的 slice 指针调用此方法也是 [undefined 行为]Read more

🔬 This is a nightly-only experimental API. (slice_index_methods)

返回此位置输出的共享引用,如果越界则会触发 panic。 Read more

🔬 This is a nightly-only experimental API. (slice_index_methods)

返回此位置输出的变量引用,如果越界则会触发 panic。 Read more

Auto Trait Implementations

Blanket Implementations

获取 selfTypeIdRead more

从拥有的值中一成不变地借用。 Read more

从拥有的值中借用。 Read more

执行转换。

执行转换。

被迭代的元素的类型。

我们将其变成哪种迭代器?

从一个值创建一个迭代器。 Read more

获得所有权后的结果类型。

通常通过克隆从借用数据中创建拥有的数据。 Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into #41263)

recently added

使用借来的数据来替换拥有的数据,通常是通过克隆。 Read more

发生转换错误时返回的类型。

执行转换。

发生转换错误时返回的类型。

执行转换。