Trait std::slice::SliceIndex1.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

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

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

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

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

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

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

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

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

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

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

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

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

Implementors

使用语法 &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)
🔬 This is a nightly-only experimental API. (slice_index_methods)
🔬 This is a nightly-only experimental API. (slice_index_methods)
🔬 This is a nightly-only experimental API. (slice_index_methods)
🔬 This is a nightly-only experimental API. (slice_index_methods)
🔬 This is a nightly-only experimental API. (slice_index_methods)

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

从字节范围 [begin,len) 返回给定字符串的片段。等同于 &self[begin .. len]&mut self[begin .. len]`.

此运算为 O(1)。

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

Panics

如果 begin 没有指向字符的起始字节偏移量 (由 is_char_boundary 定义),或者 begin > len,则为 Panics。

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

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

返回整个字符串的片段,即返回 &self&mut self。相当于 &self[0 .. len]&mut self[0 .. len]. 与其他索引操作不同,此操作永远不能 panic。

此运算为 O(1)。

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

等效于 &self[0 .. len]&mut self[0 .. len]

🔬 This is a nightly-only experimental API. (slice_index_methods)
🔬 This is a nightly-only experimental API. (slice_index_methods)
🔬 This is a nightly-only experimental API. (slice_index_methods)
🔬 This is a nightly-only experimental API. (slice_index_methods)
🔬 This is a nightly-only experimental API. (slice_index_methods)
🔬 This is a nightly-only experimental API. (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

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

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

从字节范围 [0end) 返回给定字符串的片段。 等效于 &self[0 .. end]&mut self[0 .. end]

此运算为 O(1)。

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

Panics

如果 end 没有指向字符的起始字节偏移量 (由 is_char_boundary 定义),或者 end > len,则为 Panics。

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

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

从字节范围 [0, end] 返回给定字符串的片段。 等效于 &self [0 .. end + 1],除非 end 具有 usize 的最大值。

此运算为 O(1)。

Panics

如果 end 没有指向字符的结束字节偏移量 (end + 1is_char_boundary 定义的起始字节偏移量,或者等于 len),或者如果 end >= len,则为 Panics。

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