Struct core::ops::RangeTo 1.0.0[−][src]
pub struct RangeTo<Idx> {
pub end: Idx,
}Expand description
范围仅排在 (..end) 之上。
RangeTo ..end 包含 x < end 的所有值。
它不能用作 Iterator,因为它没有起点。
Examples
..end 语法是 RangeTo:
assert_eq!((..5), std::ops::RangeTo { end: 5 });Run它没有 IntoIterator 实现,因此不能直接在 for 循环中使用它。
这不会编译:
// error[E0277]: the trait bound `std::ops::RangeTo<{integer}>:
// std::Iterator` 不满足
for i in ..5 {
// ...
}Run当用作 切片索引 时,RangeTo 会在 end 所指示的索引之前生成所有数组元素的切片。
let arr = [0, 1, 2, 3, 4];
assert_eq!(arr[ .. ], [0, 1, 2, 3, 4]);
assert_eq!(arr[ .. 3], [0, 1, 2 ]); // 这是 `RangeTo`
assert_eq!(arr[ ..=3], [0, 1, 2, 3 ]);
assert_eq!(arr[1.. ], [ 1, 2, 3, 4]);
assert_eq!(arr[1.. 3], [ 1, 2 ]);
assert_eq!(arr[1..=3], [ 1, 2, 3 ]);RunFields
end: Idx范围 (exclusive) 的上限。
Implementations
1.35.0[src]pub fn contains<U>(&self, item: &U) -> bool where
Idx: PartialOrd<U>,
U: ?Sized + PartialOrd<Idx>,
pub fn contains<U>(&self, item: &U) -> bool where
Idx: PartialOrd<U>,
U: ?Sized + PartialOrd<Idx>,
Trait Implementations
slice_index_methods)返回此位置输出的共享引用,而不执行任何边界检查。
即使未使用所得的引用,使用越界索引或悬垂的 slice 指针调用此方法也是 [undefined 行为]。 Read more
slice_index_methods)返回此位置输出的变量引用,而不执行任何边界检查。
即使未使用所得的引用,使用越界索引或悬垂的 slice 指针调用此方法也是 [undefined 行为]。 Read more
slice_index_methods)返回此位置输出的共享引用,如果越界则会触发 panic。 Read more
使用语法 &self[.. end] 或 &mut self[.. end] 实现子字符串切片。
从字节范围 [0, end) 中返回给定字符串的切片。
等效于 &self[0 .. end] 或 &mut self[0 .. end]。
此运算为 O(1)。
在 1.20.0 之前,Index 和 IndexMut 的直接实现仍支持这些索引操作。
Panics
如果 end 没有指向字符的起始字节偏移量 (由 is_char_boundary 定义),或者 end > len,就会出现 panics。
slice_index_methods)返回此位置输出的共享引用,而不执行任何边界检查。
即使未使用所得的引用,使用越界索引或悬垂的 slice 指针调用此方法也是 [undefined 行为]。 Read more
slice_index_methods)返回此位置输出的变量引用,而不执行任何边界检查。
即使未使用所得的引用,使用越界索引或悬垂的 slice 指针调用此方法也是 [undefined 行为]。 Read more
slice_index_methods)返回此位置输出的共享引用,如果越界则会触发 panic。 Read more