Trait alloc::slice::SliceIndex  1.28.0[−][src]
pub unsafe trait SliceIndex<T>: Sealed where
T: ?Sized, { type Output: ?Sized; fn get(self, slice: &T) -> Option<&Self::Output>; fn get_mut(self, slice: &mut T) -> Option<&mut Self::Output>; unsafe fn get_unchecked(self, slice: *const T) -> *const Self::Output; unsafe fn get_unchecked_mut(self, slice: *mut T) -> *mut Self::Output; fn index(self, slice: &T) -> &Self::Output; fn index_mut(self, slice: &mut T) -> &mut Self::Output; }
Expand description
帮助程序 trait 用于索引操作。
trait 的实现必须针对 promise,如果 get_(mut_)unchecked 的参数是安全引用,则结果也是如此。
Associated Types
Required methods
slice_index_methods)如果在边界内,则返回此位置输出的共享引用。
slice_index_methods)如果在边界内,则对此位置的输出返回一个可变引用。
unsafe fn get_unchecked(self, slice: *const T) -> *const Self::Output
[src]
unsafe fn get_unchecked(self, slice: *const T) -> *const Self::Output
[src]slice_index_methods)返回此位置输出的共享引用,而不执行任何边界检查。
即使未使用所得的引用,使用越界索引或悬空的 slice 指针调用此方法也是 [undefined 行为]。
unsafe fn get_unchecked_mut(self, slice: *mut T) -> *mut Self::Output
[src]
unsafe fn get_unchecked_mut(self, slice: *mut T) -> *mut Self::Output
[src]slice_index_methods)返回此位置输出的变量引用,而不执行任何边界检查。
即使未使用所得的引用,使用越界索引或悬空的 slice 指针调用此方法也是 [undefined 行为]。
slice_index_methods)返回此位置输出的共享引用,如果越界则会触发 panic。
Implementations on Foreign Types
type Output = [T]
slice_index_methods)slice_index_methods)slice_index_methods)slice_index_methods)slice_index_methods)使用语法 &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。
type Output = str
slice_index_methods)slice_index_methods)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)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_index_methods)slice_index_methods)type Output = [T]
slice_index_methods)slice_index_methods)slice_index_methods)slice_index_methods)slice_index_methods)使用语法 &self[begin ..] 或 &mut self[begin ..] 实现子字符串切片。
从字节范围 [begin,len) 返回给定字符串的片段。等同于 &self[begin ..
len]或&mut self[begin ..
len]`.
此运算为 O(1)。
在 1.20.0 之前,Index 和 IndexMut 的直接实现仍支持这些索引操作。
Panics
如果 begin 没有指向字符的起始字节偏移量 (由 is_char_boundary 定义),或者 begin > len,则为 Panics。
type Output = str
slice_index_methods)slice_index_methods)pub unsafe fn get_unchecked(
    self, 
    slice: *const str
) -> *const <RangeFrom<usize> as SliceIndex<str>>::Output
[src]
pub unsafe fn get_unchecked(
    self, 
    slice: *const str
) -> *const <RangeFrom<usize> as SliceIndex<str>>::Output
[src]slice_index_methods)pub unsafe fn get_unchecked_mut(
    self, 
    slice: *mut str
) -> *mut <RangeFrom<usize> as SliceIndex<str>>::Output
[src]
pub unsafe fn get_unchecked_mut(
    self, 
    slice: *mut str
) -> *mut <RangeFrom<usize> as SliceIndex<str>>::Output
[src]slice_index_methods)slice_index_methods)slice_index_methods)type Output = [T]
slice_index_methods)slice_index_methods)slice_index_methods)slice_index_methods)slice_index_methods)type Output = [T]
slice_index_methods)slice_index_methods)slice_index_methods)slice_index_methods)slice_index_methods)使用语法 &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。
type Output = str
pub fn get(
    self, 
    slice: &str
) -> Option<&<RangeToInclusive<usize> as SliceIndex<str>>::Output>
[src]
pub fn get(
    self, 
    slice: &str
) -> Option<&<RangeToInclusive<usize> as SliceIndex<str>>::Output>
[src]slice_index_methods)pub fn get_mut(
    self, 
    slice: &mut str
) -> Option<&mut <RangeToInclusive<usize> as SliceIndex<str>>::Output>
[src]
pub fn get_mut(
    self, 
    slice: &mut str
) -> Option<&mut <RangeToInclusive<usize> as SliceIndex<str>>::Output>
[src]slice_index_methods)pub unsafe fn get_unchecked(
    self, 
    slice: *const str
) -> *const <RangeToInclusive<usize> as SliceIndex<str>>::Output
[src]
pub unsafe fn get_unchecked(
    self, 
    slice: *const str
) -> *const <RangeToInclusive<usize> as SliceIndex<str>>::Output
[src]slice_index_methods)pub unsafe fn get_unchecked_mut(
    self, 
    slice: *mut str
) -> *mut <RangeToInclusive<usize> as SliceIndex<str>>::Output
[src]
pub unsafe fn get_unchecked_mut(
    self, 
    slice: *mut str
) -> *mut <RangeToInclusive<usize> as SliceIndex<str>>::Output
[src]slice_index_methods)slice_index_methods)pub fn index_mut(
    self, 
    slice: &mut str
) -> &mut <RangeToInclusive<usize> as SliceIndex<str>>::Output
[src]
pub fn index_mut(
    self, 
    slice: &mut str
) -> &mut <RangeToInclusive<usize> as SliceIndex<str>>::Output
[src]slice_index_methods)使用语法 &self[begin .. end] 或 &mut self[begin .. end] 实现子字符串切片。
从字节范围 [begin,end`) 返回给定字符串的片段。
此运算为 O(1)。
在 1.20.0 之前,Index 和 IndexMut 的直接实现仍支持这些索引操作。
Panics
如果 begin 或 end 未指向字符的起始字节偏移量 (由 is_char_boundary 定义),begin > end 或 end > 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
type Output = str
slice_index_methods)slice_index_methods)pub unsafe fn get_unchecked(
    self, 
    slice: *const str
) -> *const <Range<usize> as SliceIndex<str>>::Output
[src]
pub unsafe fn get_unchecked(
    self, 
    slice: *const str
) -> *const <Range<usize> as SliceIndex<str>>::Output
[src]slice_index_methods)pub unsafe fn get_unchecked_mut(
    self, 
    slice: *mut str
) -> *mut <Range<usize> as SliceIndex<str>>::Output
[src]
pub unsafe fn get_unchecked_mut(
    self, 
    slice: *mut str
) -> *mut <Range<usize> as SliceIndex<str>>::Output
[src]slice_index_methods)slice_index_methods)slice_index_methods)type Output = [T]
slice_index_methods)slice_index_methods)slice_index_methods)slice_index_methods)slice_index_methods)使用语法 &self[..] 或 &mut self[..] 实现子字符串切片。
返回整个字符串的片段,即返回 &self 或 &mut self。相当于 &self[0 .. len] 或 &mut self[0 .. len].
与其他索引操作不同,此操作永远不能 panic。
此运算为 O(1)。
在 1.20.0 之前,Index 和 IndexMut 的直接实现仍支持这些索引操作。
等效于 &self[0 .. len] 或 &mut self[0 .. len]。
type Output = str
slice_index_methods)slice_index_methods)pub unsafe fn get_unchecked(
    self, 
    slice: *const str
) -> *const <RangeFull as SliceIndex<str>>::Output
[src]
pub unsafe fn get_unchecked(
    self, 
    slice: *const str
) -> *const <RangeFull as SliceIndex<str>>::Output
[src]slice_index_methods)pub unsafe fn get_unchecked_mut(
    self, 
    slice: *mut str
) -> *mut <RangeFull as SliceIndex<str>>::Output
[src]
pub unsafe fn get_unchecked_mut(
    self, 
    slice: *mut str
) -> *mut <RangeFull as SliceIndex<str>>::Output
[src]slice_index_methods)slice_index_methods)slice_index_methods)使用语法 &self[begin ..= end] 或 &mut self[begin ..= end] 实现子字符串切片。
从字节范围 [begin, end] 返回给定字符串的片段。等效于 &self [begin .. end + 1] 或 &mut self[begin .. end + 1],除非 end 具有 usize 的最大值。
此运算为 O(1)。
Panics
Panics,如果 begin 不指向字符的起始字节偏移 (由 is_char_boundary 定义),如果 end 不指向字符的终止字节偏移 (end + 1 是起始字节偏移或等于 len),如果 begin > end,如果是 end >= len。
type Output = str
slice_index_methods)pub fn get_mut(
    self, 
    slice: &mut str
) -> Option<&mut <RangeInclusive<usize> as SliceIndex<str>>::Output>
[src]
pub fn get_mut(
    self, 
    slice: &mut str
) -> Option<&mut <RangeInclusive<usize> as SliceIndex<str>>::Output>
[src]slice_index_methods)pub unsafe fn get_unchecked(
    self, 
    slice: *const str
) -> *const <RangeInclusive<usize> as SliceIndex<str>>::Output
[src]
pub unsafe fn get_unchecked(
    self, 
    slice: *const str
) -> *const <RangeInclusive<usize> as SliceIndex<str>>::Output
[src]slice_index_methods)pub unsafe fn get_unchecked_mut(
    self, 
    slice: *mut str
) -> *mut <RangeInclusive<usize> as SliceIndex<str>>::Output
[src]
pub unsafe fn get_unchecked_mut(
    self, 
    slice: *mut str
) -> *mut <RangeInclusive<usize> as SliceIndex<str>>::Output
[src]slice_index_methods)slice_index_methods)pub fn index_mut(
    self, 
    slice: &mut str
) -> &mut <RangeInclusive<usize> as SliceIndex<str>>::Output
[src]
pub fn index_mut(
    self, 
    slice: &mut str
) -> &mut <RangeInclusive<usize> as SliceIndex<str>>::Output
[src]slice_index_methods)type Output = [T]
slice_index_methods)slice_index_methods)slice_index_methods)slice_index_methods)slice_index_methods)Implementors
type Output = [T]
slice_index_methods)slice_index_methods)pub unsafe fn get_unchecked(
    self, 
    slice: *const [T]
) -> *const <(Bound<usize>, Bound<usize>) as SliceIndex<[T]>>::Output
[src]
pub unsafe fn get_unchecked(
    self, 
    slice: *const [T]
) -> *const <(Bound<usize>, Bound<usize>) as SliceIndex<[T]>>::Output
[src]slice_index_methods)pub unsafe fn get_unchecked_mut(
    self, 
    slice: *mut [T]
) -> *mut <(Bound<usize>, Bound<usize>) as SliceIndex<[T]>>::Output
[src]
pub unsafe fn get_unchecked_mut(
    self, 
    slice: *mut [T]
) -> *mut <(Bound<usize>, Bound<usize>) as SliceIndex<[T]>>::Output
[src]slice_index_methods)slice_index_methods)type Output = T
slice_index_methods)slice_index_methods)slice_index_methods)slice_index_methods)slice_index_methods)