Struct std::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 循环中使用它。
这不会编译:
// 错误 [E0277]: trait bound`std::RangeTo <{integer}>: // std::Iterator` 不满足 for i in ..5 { // ... }Run
当用作 slicing index 时,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 ]);Run
Fields
end: Idx范围 (exclusive) 的上限。
Implementations
pub fn contains<U>(&self, item: &U) -> bool where
    U: PartialOrd<Idx> + ?Sized,
    Idx: PartialOrd<U>, 
1.35.0[src]
pub fn contains<U>(&self, item: &U) -> bool where
    U: PartialOrd<Idx> + ?Sized,
    Idx: PartialOrd<U>, 
1.35.0[src]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。
pub unsafe fn get_unchecked(
    self, 
    slice: *const str
) -> *const <RangeTo<usize> as SliceIndex<str>>::Output
[src]
pub unsafe fn get_unchecked(
    self, 
    slice: *const str
) -> *const <RangeTo<usize> as SliceIndex<str>>::Output
[src]slice_index_methods)返回此位置输出的共享引用,而不执行任何边界检查。
即使未使用所得的引用,使用越界索引或悬空的 slice 指针调用此方法也是 [undefined 行为]。 Read more
pub unsafe fn get_unchecked_mut(
    self, 
    slice: *mut str
) -> *mut <RangeTo<usize> as SliceIndex<str>>::Output
[src]
pub unsafe fn get_unchecked_mut(
    self, 
    slice: *mut str
) -> *mut <RangeTo<usize> as SliceIndex<str>>::Output
[src]slice_index_methods)返回此位置输出的变量引用,而不执行任何边界检查。
即使未使用所得的引用,使用越界索引或悬空的 slice 指针调用此方法也是 [undefined 行为]。 Read more
slice_index_methods)返回此位置输出的共享引用,如果越界则会触发 panic。 Read more