Struct std::ops::RangeToInclusive1.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 循环中使用它。这不会编译:

// 错误 [E0277]: trait bound`std::RangeToInclusive <{integer}>:
// std::Iterator` 不满足
for i in ..=5 {
    // ...
}
Run

当用作 slicing index 时,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   ]);
Run

Fields

end: Idx

范围 (inclusive) 的上限

Implementations

如果范围中包含 item,则返回 true

Examples

assert!( (..=5).contains(&-1_000_000_000));
assert!( (..=5).contains(&5));
assert!(!(..=5).contains(&6));

assert!( (..=1.0).contains(&1.0));
assert!(!(..=1.0).contains(&f32::NAN));
assert!(!(..=f32::NAN).contains(&0.5));
Run

Trait Implementations

返回值的副本。 Read more

source 执行复制分配。 Read more

使用给定的格式化程序格式化该值。 Read more

将该值输入给定的 HasherRead more

将这种类型的切片送入给定的 Hasher 中。 Read more

索引后返回的类型。

执行索引 (container[index]) 操作。 Read more

执行可变索引 (container[index]) 操作。 Read more

此方法测试 selfother 值是否相等,并由 == 使用。 Read more

此方法测试 !=

开始索引绑定。 Read more

结束索引绑定。 Read more

如果范围中包含 item,则返回 trueRead more

开始索引绑定。 Read more

结束索引绑定。 Read more

如果范围中包含 item,则返回 trueRead more

方法返回的输出类型。

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

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

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

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

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

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

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

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

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

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

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

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

使用语法 &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)

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

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

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

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

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

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

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

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

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

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

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

Auto Trait Implementations

Blanket Implementations

获取 selfTypeIdRead more

从拥有的值中一成不变地借用。 Read more

从拥有的值中借用。 Read more

执行转换。

执行转换。

获得所有权后的结果类型。

通常通过克隆从借用数据中创建拥有的数据。 Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into #41263)

recently added

使用借来的数据来替换拥有的数据,通常是通过克隆。 Read more

发生转换错误时返回的类型。

执行转换。

发生转换错误时返回的类型。

执行转换。