pub struct Range<Idx> {
pub start: Idx,
pub end: Idx,
}
Expand description
(half-open) 范围包括在 (start..end
) 之下和仅在 (start..end
) 之上。
范围 start..end
包含 start <= x < end
的所有值。
如果为 start >= end
,则为空。
Examples
start..end
语法是 Range
:
assert_eq!((3..5), std::ops::Range { start: 3, end: 5 });
assert_eq!(3 + 4 + 5, (3..6).sum());
Runlet 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 ]);
assert_eq!(arr[1.. ], [ 1, 2, 3, 4]);
assert_eq!(arr[1.. 3], [ 1, 2 ]); // 这是 `Range`
assert_eq!(arr[1..=3], [ 1, 2, 3 ]);
RunFields§
§start: Idx
范围的下限 (包括)。
end: Idx
范围 (exclusive) 的上限。
Implementations§
source§impl<Idx> Range<Idx>where
Idx: PartialOrd<Idx>,
impl<Idx> Range<Idx>where Idx: PartialOrd<Idx>,
1.35.0 · sourcepub fn contains<U>(&self, item: &U) -> boolwhere
Idx: PartialOrd<U>,
U: PartialOrd<Idx> + ?Sized,
pub fn contains<U>(&self, item: &U) -> boolwhere Idx: PartialOrd<U>, U: PartialOrd<Idx> + ?Sized,
如果范围中包含 item
,则返回 true
。
Examples
assert!(!(3..5).contains(&2));
assert!( (3..5).contains(&3));
assert!( (3..5).contains(&4));
assert!(!(3..5).contains(&5));
assert!(!(3..3).contains(&3));
assert!(!(3..2).contains(&3));
assert!( (0.0..1.0).contains(&0.5));
assert!(!(0.0..1.0).contains(&f32::NAN));
assert!(!(0.0..f32::NAN).contains(&0.5));
assert!(!(f32::NAN..1.0).contains(&0.5));
RunTrait Implementations§
source§impl<A> DoubleEndedIterator for Range<A>where
A: Step,
impl<A> DoubleEndedIterator for Range<A>where A: Step,
source§fn advance_back_by(&mut self, n: usize) -> Result<(), NonZeroUsize>
fn advance_back_by(&mut self, n: usize) -> Result<(), NonZeroUsize>
🔬This is a nightly-only experimental API. (
iter_advance_by
#77404)通过
n
元素从后向前推进迭代器。 Read more1.27.0 · source§fn try_rfold<B, F, R>(&mut self, init: B, f: F) -> Rwhere
Self: Sized,
F: FnMut(B, Self::Item) -> R,
R: Try<Output = B>,
fn try_rfold<B, F, R>(&mut self, init: B, f: F) -> Rwhere Self: Sized, F: FnMut(B, Self::Item) -> R, R: Try<Output = B>,
这是
Iterator::try_fold()
的反向版本:它从迭代器的后面开始接收元素。 Read moresource§impl ExactSizeIterator for Range<i16>
impl ExactSizeIterator for Range<i16>
source§impl ExactSizeIterator for Range<i32>
impl ExactSizeIterator for Range<i32>
source§impl ExactSizeIterator for Range<i8>
impl ExactSizeIterator for Range<i8>
source§impl ExactSizeIterator for Range<isize>
impl ExactSizeIterator for Range<isize>
source§impl ExactSizeIterator for Range<u16>
impl ExactSizeIterator for Range<u16>
source§impl ExactSizeIterator for Range<u32>
impl ExactSizeIterator for Range<u32>
source§impl ExactSizeIterator for Range<u8>
impl ExactSizeIterator for Range<u8>
source§impl ExactSizeIterator for Range<usize>
impl ExactSizeIterator for Range<usize>
source§impl<A> Iterator for Range<A>where
A: Step,
impl<A> Iterator for Range<A>where A: Step,
source§fn is_sorted(self) -> bool
fn is_sorted(self) -> bool
🔬This is a nightly-only experimental API. (
is_sorted
#53485)检查此迭代器的元素是否已排序。 Read more
source§fn advance_by(&mut self, n: usize) -> Result<(), NonZeroUsize>
fn advance_by(&mut self, n: usize) -> Result<(), NonZeroUsize>
🔬This is a nightly-only experimental API. (
iter_advance_by
#77404)通过
n
元素使迭代器前进。 Read moresource§fn next_chunk<const N: usize>(
&mut self
) -> Result<[Self::Item; N], IntoIter<Self::Item, N>>where
Self: Sized,
fn next_chunk<const N: usize>( &mut self ) -> Result<[Self::Item; N], IntoIter<Self::Item, N>>where Self: Sized,
🔬This is a nightly-only experimental API. (
iter_next_chunk
#98326)推进迭代器并返回包含下一个
N
值的数组。 Read more1.28.0 · source§fn step_by(self, step: usize) -> StepBy<Self> ⓘwhere
Self: Sized,
fn step_by(self, step: usize) -> StepBy<Self> ⓘwhere Self: Sized,
创建一个从同一点开始的迭代器,但在每次迭代时以给定的数量逐步执行。 Read more
source§fn chain<U>(self, other: U) -> Chain<Self, <U as IntoIterator>::IntoIter> ⓘwhere
Self: Sized,
U: IntoIterator<Item = Self::Item>,
fn chain<U>(self, other: U) -> Chain<Self, <U as IntoIterator>::IntoIter> ⓘwhere Self: Sized, U: IntoIterator<Item = Self::Item>,
接受两个迭代器,并依次在两个迭代器上创建一个新的迭代器。 Read more
source§fn zip<U>(self, other: U) -> Zip<Self, <U as IntoIterator>::IntoIter> ⓘwhere
Self: Sized,
U: IntoIterator,
fn zip<U>(self, other: U) -> Zip<Self, <U as IntoIterator>::IntoIter> ⓘwhere Self: Sized, U: IntoIterator,
将两个迭代器压缩为成对的单个迭代器。 Read more
source§fn intersperse_with<G>(self, separator: G) -> IntersperseWith<Self, G> ⓘwhere
Self: Sized,
G: FnMut() -> Self::Item,
fn intersperse_with<G>(self, separator: G) -> IntersperseWith<Self, G> ⓘwhere Self: Sized, G: FnMut() -> Self::Item,
🔬This is a nightly-only experimental API. (
iter_intersperse
#79524)创建一个新的迭代器,该迭代器将
separator
生成的项放在原始迭代器的相邻项之间。 Read moresource§fn map<B, F>(self, f: F) -> Map<Self, F> ⓘwhere
Self: Sized,
F: FnMut(Self::Item) -> B,
fn map<B, F>(self, f: F) -> Map<Self, F> ⓘwhere Self: Sized, F: FnMut(Self::Item) -> B,
获取一个闭包并创建一个迭代器,该迭代器在每个元素上调用该闭包。 Read more
1.21.0 · source§fn for_each<F>(self, f: F)where
Self: Sized,
F: FnMut(Self::Item),
fn for_each<F>(self, f: F)where Self: Sized, F: FnMut(Self::Item),
在迭代器的每个元素上调用一个闭包。 Read more
source§fn filter<P>(self, predicate: P) -> Filter<Self, P> ⓘwhere
Self: Sized,
P: FnMut(&Self::Item) -> bool,
fn filter<P>(self, predicate: P) -> Filter<Self, P> ⓘwhere Self: Sized, P: FnMut(&Self::Item) -> bool,
创建一个迭代器,该迭代器使用闭包确定是否应产生元素。 Read more
source§fn filter_map<B, F>(self, f: F) -> FilterMap<Self, F> ⓘwhere
Self: Sized,
F: FnMut(Self::Item) -> Option<B>,
fn filter_map<B, F>(self, f: F) -> FilterMap<Self, F> ⓘwhere Self: Sized, F: FnMut(Self::Item) -> Option<B>,
创建一个同时过滤和映射的迭代器。 Read more
source§fn enumerate(self) -> Enumerate<Self> ⓘwhere
Self: Sized,
fn enumerate(self) -> Enumerate<Self> ⓘwhere Self: Sized,
创建一个迭代器,该迭代器给出当前迭代次数以及下一个值。 Read more
source§fn skip_while<P>(self, predicate: P) -> SkipWhile<Self, P> ⓘwhere
Self: Sized,
P: FnMut(&Self::Item) -> bool,
fn skip_while<P>(self, predicate: P) -> SkipWhile<Self, P> ⓘwhere Self: Sized, P: FnMut(&Self::Item) -> bool,
source§fn take_while<P>(self, predicate: P) -> TakeWhile<Self, P> ⓘwhere
Self: Sized,
P: FnMut(&Self::Item) -> bool,
fn take_while<P>(self, predicate: P) -> TakeWhile<Self, P> ⓘwhere Self: Sized, P: FnMut(&Self::Item) -> bool,
创建一个迭代器,该迭代器根据谓词产生元素。 Read more
1.57.0 · source§fn map_while<B, P>(self, predicate: P) -> MapWhile<Self, P> ⓘwhere
Self: Sized,
P: FnMut(Self::Item) -> Option<B>,
fn map_while<B, P>(self, predicate: P) -> MapWhile<Self, P> ⓘwhere Self: Sized, P: FnMut(Self::Item) -> Option<B>,
创建一个迭代器,该迭代器均基于谓词和映射生成元素。 Read more
source§fn take(self, n: usize) -> Take<Self> ⓘwhere
Self: Sized,
fn take(self, n: usize) -> Take<Self> ⓘwhere Self: Sized,
创建一个迭代器,它产生第一个
n
元素,如果底层迭代器提前结束,则产生更少的元素。 Read moresource§fn scan<St, B, F>(self, initial_state: St, f: F) -> Scan<Self, St, F> ⓘwhere
Self: Sized,
F: FnMut(&mut St, Self::Item) -> Option<B>,
fn scan<St, B, F>(self, initial_state: St, f: F) -> Scan<Self, St, F> ⓘwhere Self: Sized, F: FnMut(&mut St, Self::Item) -> Option<B>,
source§fn flat_map<U, F>(self, f: F) -> FlatMap<Self, U, F> ⓘwhere
Self: Sized,
U: IntoIterator,
F: FnMut(Self::Item) -> U,
fn flat_map<U, F>(self, f: F) -> FlatMap<Self, U, F> ⓘwhere Self: Sized, U: IntoIterator, F: FnMut(Self::Item) -> U,
创建一个迭代器,其工作方式类似于 map,但它会将嵌套的结构展平。 Read more
source§fn inspect<F>(self, f: F) -> Inspect<Self, F> ⓘwhere
Self: Sized,
F: FnMut(&Self::Item),
fn inspect<F>(self, f: F) -> Inspect<Self, F> ⓘwhere Self: Sized, F: FnMut(&Self::Item),
对迭代器的每个元素执行某些操作,将值传递给它。 Read more
source§fn collect_into<E>(self, collection: &mut E) -> &mut Ewhere
E: Extend<Self::Item>,
Self: Sized,
fn collect_into<E>(self, collection: &mut E) -> &mut Ewhere E: Extend<Self::Item>, Self: Sized,
🔬This is a nightly-only experimental API. (
iter_collect_into
#94780)将迭代器中的所有项收集到一个集合中。 Read more
source§fn partition<B, F>(self, f: F) -> (B, B)where
Self: Sized,
B: Default + Extend<Self::Item>,
F: FnMut(&Self::Item) -> bool,
fn partition<B, F>(self, f: F) -> (B, B)where Self: Sized, B: Default + Extend<Self::Item>, F: FnMut(&Self::Item) -> bool,
消耗一个迭代器,从中创建两个集合。 Read more
source§fn partition_in_place<'a, T, P>(self, predicate: P) -> usizewhere
T: 'a,
Self: Sized + DoubleEndedIterator<Item = &'a mut T>,
P: FnMut(&T) -> bool,
fn partition_in_place<'a, T, P>(self, predicate: P) -> usizewhere T: 'a, Self: Sized + DoubleEndedIterator<Item = &'a mut T>, P: FnMut(&T) -> bool,
🔬This is a nightly-only experimental API. (
iter_partition_in_place
#62543)source§fn is_partitioned<P>(self, predicate: P) -> boolwhere
Self: Sized,
P: FnMut(Self::Item) -> bool,
fn is_partitioned<P>(self, predicate: P) -> boolwhere Self: Sized, P: FnMut(Self::Item) -> bool,
🔬This is a nightly-only experimental API. (
iter_is_partitioned
#62544)1.27.0 · source§fn try_fold<B, F, R>(&mut self, init: B, f: F) -> Rwhere
Self: Sized,
F: FnMut(B, Self::Item) -> R,
R: Try<Output = B>,
fn try_fold<B, F, R>(&mut self, init: B, f: F) -> Rwhere Self: Sized, F: FnMut(B, Self::Item) -> R, R: Try<Output = B>,
一个迭代器方法,它只要成功返回就应用函数,并产生单个最终值。 Read more
1.27.0 · source§fn try_for_each<F, R>(&mut self, f: F) -> Rwhere
Self: Sized,
F: FnMut(Self::Item) -> R,
R: Try<Output = ()>,
fn try_for_each<F, R>(&mut self, f: F) -> Rwhere Self: Sized, F: FnMut(Self::Item) -> R, R: Try<Output = ()>,
一个迭代器方法,该方法将一个容易犯错的函数应用于迭代器中的每个项,在第一个错误处停止并返回该错误。 Read more
source§fn fold<B, F>(self, init: B, f: F) -> Bwhere
Self: Sized,
F: FnMut(B, Self::Item) -> B,
fn fold<B, F>(self, init: B, f: F) -> Bwhere Self: Sized, F: FnMut(B, Self::Item) -> B,
通过应用操作将每个元素
fold
到一个累加器中,返回最终结果。 Read more1.51.0 · source§fn reduce<F>(self, f: F) -> Option<Self::Item>where
Self: Sized,
F: FnMut(Self::Item, Self::Item) -> Self::Item,
fn reduce<F>(self, f: F) -> Option<Self::Item>where Self: Sized, F: FnMut(Self::Item, Self::Item) -> Self::Item,
通过重复应用缩减操作,将元素缩减为一个。 Read more
source§fn try_reduce<F, R>(
&mut self,
f: F
) -> <<R as Try>::Residual as Residual<Option<<R as Try>::Output>>>::TryTypewhere
Self: Sized,
F: FnMut(Self::Item, Self::Item) -> R,
R: Try<Output = Self::Item>,
<R as Try>::Residual: Residual<Option<Self::Item>>,
fn try_reduce<F, R>( &mut self, f: F ) -> <<R as Try>::Residual as Residual<Option<<R as Try>::Output>>>::TryTypewhere Self: Sized, F: FnMut(Self::Item, Self::Item) -> R, R: Try<Output = Self::Item>, <R as Try>::Residual: Residual<Option<Self::Item>>,
🔬This is a nightly-only experimental API. (
iterator_try_reduce
#87053)通过重复应用 Reduce 操作,将元素归约为单个元素。
如果闭包返回失败,则失败会立即传播给调用者。 Read more
source§fn all<F>(&mut self, f: F) -> boolwhere
Self: Sized,
F: FnMut(Self::Item) -> bool,
fn all<F>(&mut self, f: F) -> boolwhere Self: Sized, F: FnMut(Self::Item) -> bool,
测试迭代器的每个元素是否与谓词匹配。 Read more
source§fn any<F>(&mut self, f: F) -> boolwhere
Self: Sized,
F: FnMut(Self::Item) -> bool,
fn any<F>(&mut self, f: F) -> boolwhere Self: Sized, F: FnMut(Self::Item) -> bool,
测试迭代器的任何元素是否与谓词匹配。 Read more
source§fn find<P>(&mut self, predicate: P) -> Option<Self::Item>where
Self: Sized,
P: FnMut(&Self::Item) -> bool,
fn find<P>(&mut self, predicate: P) -> Option<Self::Item>where Self: Sized, P: FnMut(&Self::Item) -> bool,
搜索满足谓词的迭代器的元素。 Read more
1.30.0 · source§fn find_map<B, F>(&mut self, f: F) -> Option<B>where
Self: Sized,
F: FnMut(Self::Item) -> Option<B>,
fn find_map<B, F>(&mut self, f: F) -> Option<B>where Self: Sized, F: FnMut(Self::Item) -> Option<B>,
将函数应用于迭代器的元素,并返回第一个非 None 的结果。 Read more
source§fn try_find<F, R>(
&mut self,
f: F
) -> <<R as Try>::Residual as Residual<Option<Self::Item>>>::TryTypewhere
Self: Sized,
F: FnMut(&Self::Item) -> R,
R: Try<Output = bool>,
<R as Try>::Residual: Residual<Option<Self::Item>>,
fn try_find<F, R>( &mut self, f: F ) -> <<R as Try>::Residual as Residual<Option<Self::Item>>>::TryTypewhere Self: Sized, F: FnMut(&Self::Item) -> R, R: Try<Output = bool>, <R as Try>::Residual: Residual<Option<Self::Item>>,
🔬This is a nightly-only experimental API. (
try_find
#63178)将函数应用于迭代器的元素,并返回第一个为 true 的结果或第一个错误。 Read more
source§fn position<P>(&mut self, predicate: P) -> Option<usize>where
Self: Sized,
P: FnMut(Self::Item) -> bool,
fn position<P>(&mut self, predicate: P) -> Option<usize>where Self: Sized, P: FnMut(Self::Item) -> bool,
在迭代器中搜索元素,并返回其索引。 Read more
1.6.0 · source§fn max_by_key<B, F>(self, f: F) -> Option<Self::Item>where
B: Ord,
Self: Sized,
F: FnMut(&Self::Item) -> B,
fn max_by_key<B, F>(self, f: F) -> Option<Self::Item>where B: Ord, Self: Sized, F: FnMut(&Self::Item) -> B,
返回给出指定函数最大值的元素。 Read more
1.15.0 · source§fn max_by<F>(self, compare: F) -> Option<Self::Item>where
Self: Sized,
F: FnMut(&Self::Item, &Self::Item) -> Ordering,
fn max_by<F>(self, compare: F) -> Option<Self::Item>where Self: Sized, F: FnMut(&Self::Item, &Self::Item) -> Ordering,
返回给出相对于指定比较函数的最大值的元素。 Read more
1.6.0 · source§fn min_by_key<B, F>(self, f: F) -> Option<Self::Item>where
B: Ord,
Self: Sized,
F: FnMut(&Self::Item) -> B,
fn min_by_key<B, F>(self, f: F) -> Option<Self::Item>where B: Ord, Self: Sized, F: FnMut(&Self::Item) -> B,
返回给出指定函数中最小值的元素。 Read more
1.15.0 · source§fn min_by<F>(self, compare: F) -> Option<Self::Item>where
Self: Sized,
F: FnMut(&Self::Item, &Self::Item) -> Ordering,
fn min_by<F>(self, compare: F) -> Option<Self::Item>where Self: Sized, F: FnMut(&Self::Item, &Self::Item) -> Ordering,
返回给出相对于指定比较函数的最小值的元素。 Read more
source§fn unzip<A, B, FromA, FromB>(self) -> (FromA, FromB)where
FromA: Default + Extend<A>,
FromB: Default + Extend<B>,
Self: Sized + Iterator<Item = (A, B)>,
fn unzip<A, B, FromA, FromB>(self) -> (FromA, FromB)where FromA: Default + Extend<A>, FromB: Default + Extend<B>, Self: Sized + Iterator<Item = (A, B)>,
将成对的迭代器转换为一对容器。 Read more
1.36.0 · source§fn copied<'a, T>(self) -> Copied<Self> ⓘwhere
T: 'a + Copy,
Self: Sized + Iterator<Item = &'a T>,
fn copied<'a, T>(self) -> Copied<Self> ⓘwhere T: 'a + Copy, Self: Sized + Iterator<Item = &'a T>,
创建一个迭代器,该迭代器将复制其所有元素。 Read more
source§fn cloned<'a, T>(self) -> Cloned<Self> ⓘwhere
T: 'a + Clone,
Self: Sized + Iterator<Item = &'a T>,
fn cloned<'a, T>(self) -> Cloned<Self> ⓘwhere T: 'a + Clone, Self: Sized + Iterator<Item = &'a T>,
创建一个迭代器,该迭代器将克隆所有元素。 Read more
source§fn array_chunks<const N: usize>(self) -> ArrayChunks<Self, N> ⓘwhere
Self: Sized,
fn array_chunks<const N: usize>(self) -> ArrayChunks<Self, N> ⓘwhere Self: Sized,
🔬This is a nightly-only experimental API. (
iter_array_chunks
#100450)一次返回迭代器的
N
个元素的迭代器。 Read more1.11.0 · source§fn product<P>(self) -> Pwhere
Self: Sized,
P: Product<Self::Item>,
fn product<P>(self) -> Pwhere Self: Sized, P: Product<Self::Item>,
遍历整个迭代器,将所有元素相乘 Read more
source§fn cmp_by<I, F>(self, other: I, cmp: F) -> Orderingwhere
Self: Sized,
I: IntoIterator,
F: FnMut(Self::Item, <I as IntoIterator>::Item) -> Ordering,
fn cmp_by<I, F>(self, other: I, cmp: F) -> Orderingwhere Self: Sized, I: IntoIterator, F: FnMut(Self::Item, <I as IntoIterator>::Item) -> Ordering,
🔬This is a nightly-only experimental API. (
iter_order_by
#64295)1.5.0 · source§fn partial_cmp<I>(self, other: I) -> Option<Ordering>where
I: IntoIterator,
Self::Item: PartialOrd<<I as IntoIterator>::Item>,
Self: Sized,
fn partial_cmp<I>(self, other: I) -> Option<Ordering>where I: IntoIterator, Self::Item: PartialOrd<<I as IntoIterator>::Item>, Self: Sized,
Lexicographically 将此
Iterator
的 PartialOrd
元素与另一个 PartialOrd
的元素进行比较。
比较的工作方式类似于短路评估,返回结果而不比较其余元素。
一旦可以确定订单,评估就会停止并返回结果。 Read moresource§fn partial_cmp_by<I, F>(self, other: I, partial_cmp: F) -> Option<Ordering>where
Self: Sized,
I: IntoIterator,
F: FnMut(Self::Item, <I as IntoIterator>::Item) -> Option<Ordering>,
fn partial_cmp_by<I, F>(self, other: I, partial_cmp: F) -> Option<Ordering>where Self: Sized, I: IntoIterator, F: FnMut(Self::Item, <I as IntoIterator>::Item) -> Option<Ordering>,
🔬This is a nightly-only experimental API. (
iter_order_by
#64295)1.5.0 · source§fn eq<I>(self, other: I) -> boolwhere
I: IntoIterator,
Self::Item: PartialEq<<I as IntoIterator>::Item>,
Self: Sized,
fn eq<I>(self, other: I) -> boolwhere I: IntoIterator, Self::Item: PartialEq<<I as IntoIterator>::Item>, Self: Sized,
source§fn eq_by<I, F>(self, other: I, eq: F) -> boolwhere
Self: Sized,
I: IntoIterator,
F: FnMut(Self::Item, <I as IntoIterator>::Item) -> bool,
fn eq_by<I, F>(self, other: I, eq: F) -> boolwhere Self: Sized, I: IntoIterator, F: FnMut(Self::Item, <I as IntoIterator>::Item) -> bool,
🔬This is a nightly-only experimental API. (
iter_order_by
#64295)1.5.0 · source§fn ne<I>(self, other: I) -> boolwhere
I: IntoIterator,
Self::Item: PartialEq<<I as IntoIterator>::Item>,
Self: Sized,
fn ne<I>(self, other: I) -> boolwhere I: IntoIterator, Self::Item: PartialEq<<I as IntoIterator>::Item>, Self: Sized,
1.5.0 · source§fn lt<I>(self, other: I) -> boolwhere
I: IntoIterator,
Self::Item: PartialOrd<<I as IntoIterator>::Item>,
Self: Sized,
fn lt<I>(self, other: I) -> boolwhere I: IntoIterator, Self::Item: PartialOrd<<I as IntoIterator>::Item>, Self: Sized,
1.5.0 · source§fn le<I>(self, other: I) -> boolwhere
I: IntoIterator,
Self::Item: PartialOrd<<I as IntoIterator>::Item>,
Self: Sized,
fn le<I>(self, other: I) -> boolwhere I: IntoIterator, Self::Item: PartialOrd<<I as IntoIterator>::Item>, Self: Sized,
1.5.0 · source§fn gt<I>(self, other: I) -> boolwhere
I: IntoIterator,
Self::Item: PartialOrd<<I as IntoIterator>::Item>,
Self: Sized,
fn gt<I>(self, other: I) -> boolwhere I: IntoIterator, Self::Item: PartialOrd<<I as IntoIterator>::Item>, Self: Sized,
1.5.0 · source§fn ge<I>(self, other: I) -> boolwhere
I: IntoIterator,
Self::Item: PartialOrd<<I as IntoIterator>::Item>,
Self: Sized,
fn ge<I>(self, other: I) -> boolwhere I: IntoIterator, Self::Item: PartialOrd<<I as IntoIterator>::Item>, Self: Sized,
source§fn is_sorted_by<F>(self, compare: F) -> boolwhere
Self: Sized,
F: FnMut(&Self::Item, &Self::Item) -> Option<Ordering>,
fn is_sorted_by<F>(self, compare: F) -> boolwhere Self: Sized, F: FnMut(&Self::Item, &Self::Item) -> Option<Ordering>,
🔬This is a nightly-only experimental API. (
is_sorted
#53485)检查此迭代器的元素是否使用给定的比较器函数进行排序。 Read more
source§fn is_sorted_by_key<F, K>(self, f: F) -> boolwhere
Self: Sized,
F: FnMut(Self::Item) -> K,
K: PartialOrd<K>,
fn is_sorted_by_key<F, K>(self, f: F) -> boolwhere Self: Sized, F: FnMut(Self::Item) -> K, K: PartialOrd<K>,
🔬This is a nightly-only experimental API. (
is_sorted
#53485)检查此迭代器的元素是否使用给定的键提取函数进行排序。 Read more
1.28.0 · source§impl<T> RangeBounds<T> for Range<&T>
impl<T> RangeBounds<T> for Range<&T>
1.28.0 · source§impl<T> RangeBounds<T> for Range<T>
impl<T> RangeBounds<T> for Range<T>
1.15.0 (const: unstable) · source§impl<T> SliceIndex<[T]> for Range<usize>
impl<T> SliceIndex<[T]> for Range<usize>
const: unstable · source§fn get(self, slice: &[T]) -> Option<&[T]>
fn get(self, slice: &[T]) -> Option<&[T]>
🔬This is a nightly-only experimental API. (
slice_index_methods
)如果在边界内,则返回此位置输出的共享引用。
const: unstable · source§fn get_mut(self, slice: &mut [T]) -> Option<&mut [T]>
fn get_mut(self, slice: &mut [T]) -> Option<&mut [T]>
🔬This is a nightly-only experimental API. (
slice_index_methods
)如果在边界内,则对此位置的输出返回一个可变引用。
const: unstable · source§unsafe fn get_unchecked(self, slice: *const [T]) -> *const [T]
unsafe fn get_unchecked(self, slice: *const [T]) -> *const [T]
🔬This is a nightly-only experimental API. (
slice_index_methods
)返回此位置输出的共享引用,而不执行任何边界检查。
即使未使用所得的引用,使用越界索引或悬垂的
slice
指针调用此方法也是 [undefined 行为]。const: unstable · source§unsafe fn get_unchecked_mut(self, slice: *mut [T]) -> *mut [T]
unsafe fn get_unchecked_mut(self, slice: *mut [T]) -> *mut [T]
🔬This is a nightly-only experimental API. (
slice_index_methods
)返回此位置输出的变量引用,而不执行任何边界检查。
即使未使用所得的引用,使用越界索引或悬垂的
slice
指针调用此方法也是 [undefined 行为]。1.20.0 (const: unstable) · source§impl SliceIndex<str> for Range<usize>
impl SliceIndex<str> for Range<usize>
使用语法 &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];
Runconst: unstable · source§fn get(self, slice: &str) -> Option<&<Range<usize> as SliceIndex<str>>::Output>
fn get(self, slice: &str) -> Option<&<Range<usize> as SliceIndex<str>>::Output>
🔬This is a nightly-only experimental API. (
slice_index_methods
)如果在边界内,则返回此位置输出的共享引用。
const: unstable · source§fn get_mut(
self,
slice: &mut str
) -> Option<&mut <Range<usize> as SliceIndex<str>>::Output>
fn get_mut( self, slice: &mut str ) -> Option<&mut <Range<usize> as SliceIndex<str>>::Output>
🔬This is a nightly-only experimental API. (
slice_index_methods
)如果在边界内,则对此位置的输出返回一个可变引用。
const: unstable · source§unsafe fn get_unchecked(
self,
slice: *const str
) -> *const <Range<usize> as SliceIndex<str>>::Output
unsafe fn get_unchecked( self, slice: *const str ) -> *const <Range<usize> as SliceIndex<str>>::Output
🔬This is a nightly-only experimental API. (
slice_index_methods
)返回此位置输出的共享引用,而不执行任何边界检查。
即使未使用所得的引用,使用越界索引或悬垂的
slice
指针调用此方法也是 [undefined 行为]。const: unstable · source§unsafe fn get_unchecked_mut(
self,
slice: *mut str
) -> *mut <Range<usize> as SliceIndex<str>>::Output
unsafe fn get_unchecked_mut( self, slice: *mut str ) -> *mut <Range<usize> as SliceIndex<str>>::Output
🔬This is a nightly-only experimental API. (
slice_index_methods
)返回此位置输出的变量引用,而不执行任何边界检查。
即使未使用所得的引用,使用越界索引或悬垂的
slice
指针调用此方法也是 [undefined 行为]。impl<Idx> Eq for Range<Idx>where Idx: Eq,
impl<A> FusedIterator for Range<A>where A: Step,
impl<Idx> StructuralEq for Range<Idx>
impl<Idx> StructuralPartialEq for Range<Idx>
impl<A> TrustedLen for Range<A>where A: TrustedStep,
Auto Trait Implementations§
impl<Idx> RefUnwindSafe for Range<Idx>where Idx: RefUnwindSafe,
impl<Idx> Send for Range<Idx>where Idx: Send,
impl<Idx> Sync for Range<Idx>where Idx: Sync,
impl<Idx> Unpin for Range<Idx>where Idx: Unpin,
impl<Idx> UnwindSafe for Range<Idx>where Idx: UnwindSafe,
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
从拥有的值中借用。 Read more