Struct core::ops::RangeToInclusive 1.26.0[−][src]
pub struct RangeToInclusive<Idx> {
pub end: Idx,
}Expand description
范围仅包括 (..=end) 以上的范围。
RangeToInclusive ..=end 包含 x <= end 的所有值。
它不能用作 Iterator,因为它没有起点。
Examples
..=end 语法是 RangeToInclusive:
assert_eq!((..=5), std::ops::RangeToInclusive{ end: 5 });Run它没有 IntoIterator 实现,因此不能直接在 for 循环中使用它。这不会编译:
// error[E0277]: the trait bound `std::ops::RangeToInclusive<{integer}>:
// std::Iterator` 不满足
for i in ..=5 {
// ...
}Run当用作 切片索引 时,RangeToInclusive 会生成所有数组元素的切片,直到并包括 end 指示的索引。
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 ]); // 这是 `RangeToInclusive`
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范围的上限 (包含上限)
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
此方法测试 self 和 other 值是否相等,并由 == 使用。 Read more
此方法测试 !=。
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 + 1],除非 end 具有 usize 的最大值。
此运算为 O(1)。
Panics
如果 end 没有指向字符的结束字节偏移量 (end + 1 是 is_char_boundary 定义的起始字节偏移量,或者等于 len),或者如果 end >= len,就会出现 panics。
slice_index_methods)返回此位置输出的共享引用,而不执行任何边界检查。
即使未使用所得的引用,使用越界索引或悬垂的 slice 指针调用此方法也是 [undefined 行为]。 Read more
slice_index_methods)返回此位置输出的变量引用,而不执行任何边界检查。
即使未使用所得的引用,使用越界索引或悬垂的 slice 指针调用此方法也是 [undefined 行为]。 Read more
slice_index_methods)返回此位置输出的共享引用,如果越界则会触发 panic。 Read more