Struct std::io::Lines
BufRead 实例的行上的迭代器。
通常通过在 BufRead 上调用 lines 来创建此结构体。 请参见 lines 的文档以获取更多详细信息。
pub struct Lines<B> { /* private fields */ }Trait Implementations
impl<B: Debug> Debug for Lines<B>
fmt
使用给定的格式化程序格式化该值。
fn fmt(&self, f: &mut Formatter<'_>) -> Resultimpl<B: BufRead> Iterator for Lines<B>
Item
被迭代的元素的类型。
type Item = Result<String, Error>next
推进迭代器并返回下一个值。
fn next(&mut self) -> Option<Result<String>>next_chunk
推进迭代器并返回包含下一个 N 值的数组
fn next_chunk<const N: usize>(
&mut self
) -> Result<[Self::Item; N], IntoIter<Self::Item, N>>
where
Self: Sized,size_hint
返回迭代器剩余长度的界限。
fn size_hint(&self) -> (usize, Option<usize>)count
消耗迭代器,计算迭代次数并返回它。
fn count(self) -> usize
where
Self: Sized,last
消耗迭代器,返回最后一个元素。
fn last(self) -> Option<Self::Item>
where
Self: Sized,advance_by
通过 n 元素使迭代器前进。
fn advance_by(&mut self, n: usize) -> Result<(), NonZeroUsize>nth
返回迭代器的第 n 个元素。
fn nth(&mut self, n: usize) -> Option<Self::Item>step_by
创建一个从同一点开始的迭代器,但在每次迭代时以给定的数量逐步执行。
fn step_by(self, step: usize) -> StepBy<Self>
where
Self: Sized,chain
接受两个迭代器,并依次在两个迭代器上创建一个新的迭代器。
fn chain<U>(self, other: U) -> Chain<Self, <U as IntoIterator>::IntoIter>
where
Self: Sized,
U: IntoIterator<Item = Self::Item>,zip
将两个迭代器压缩为成对的单个迭代器。
fn zip<U>(self, other: U) -> Zip<Self, <U as IntoIterator>::IntoIter>
where
Self: Sized,
U: IntoIterator,intersperse_with
创建一个新的迭代器,该迭代器将 separator 生成的项放在原始迭代器的相邻项之间。
fn intersperse_with<G>(self, separator: G) -> IntersperseWith<Self, G>
where
Self: Sized,
G: FnMut() -> Self::Item,map
获取一个闭包并创建一个迭代器,该迭代器在每个元素上调用该闭包。
fn map<B, F>(self, f: F) -> Map<Self, F>
where
Self: Sized,
F: FnMut(Self::Item) -> B,for_each
在迭代器的每个元素上调用一个闭包。
fn for_each<F>(self, f: F)
where
Self: Sized,
F: FnMut(Self::Item),filter
创建一个迭代器,该迭代器使用闭包确定是否应产生元素。
fn filter<P>(self, predicate: P) -> Filter<Self, P>
where
Self: Sized,
P: FnMut(&Self::Item) -> bool,filter_map
创建一个同时过滤和映射的迭代器。
fn filter_map<B, F>(self, f: F) -> FilterMap<Self, F>
where
Self: Sized,
F: FnMut(Self::Item) -> Option<B>,enumerate
创建一个迭代器,该迭代器给出当前迭代次数以及下一个值。
fn enumerate(self) -> Enumerate<Self>
where
Self: Sized,peekable
创建一个迭代器,它可以使用 peek 和 peek_mut 方法查看迭代器的下一个元素而不消耗它。有关更多信息,请参见他们的文档。
fn peekable(self) -> Peekable<Self>
where
Self: Sized,skip_while
创建一个迭代器,该迭代器基于谓词 skip 元素。
fn skip_while<P>(self, predicate: P) -> SkipWhile<Self, P>
where
Self: Sized,
P: FnMut(&Self::Item) -> bool,take_while
创建一个迭代器,该迭代器根据谓词产生元素。
fn take_while<P>(self, predicate: P) -> TakeWhile<Self, P>
where
Self: Sized,
P: FnMut(&Self::Item) -> bool,map_while
创建一个迭代器,该迭代器均基于谓词和映射生成元素。
fn map_while<B, P>(self, predicate: P) -> MapWhile<Self, P>
where
Self: Sized,
P: FnMut(Self::Item) -> Option<B>,skip
创建一个跳过前 n 个元素的迭代器。
fn skip(self, n: usize) -> Skip<Self>
where
Self: Sized,take
创建一个迭代器,它产生第一个 n 元素,如果底层迭代器提前结束,则产生更少的元素。
fn take(self, n: usize) -> Take<Self>
where
Self: Sized,scan
一个迭代器适配器,它与 fold 一样保存内部状态,但与 fold 不同,它生成一个新的迭代器。
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>,flat_map
创建一个迭代器,其工作方式类似于 map,但它会将嵌套的结构展平。
fn flat_map<U, F>(self, f: F) -> FlatMap<Self, U, F>
where
Self: Sized,
U: IntoIterator,
F: FnMut(Self::Item) -> U,fuse
创建一个迭代器,该迭代器在第一个 None 之后结束。
fn fuse(self) -> Fuse<Self>
where
Self: Sized,inspect
对迭代器的每个元素执行某些操作,将值传递给它。
fn inspect<F>(self, f: F) -> Inspect<Self, F>
where
Self: Sized,
F: FnMut(&Self::Item),by_ref
借用一个迭代器,而不是使用它。
fn by_ref(&mut self) -> &mut Self
where
Self: Sized,collect
将迭代器转换为集合。
fn collect<B>(self) -> B
where
B: FromIterator<Self::Item>,
Self: Sized,collect_into
将迭代器中的所有项收集到一个集合中。
fn collect_into<E>(self, collection: &mut E) -> &mut E
where
E: Extend<Self::Item>,
Self: Sized,partition
消耗一个迭代器,从中创建两个集合。
fn partition<B, F>(self, f: F) -> (B, B)
where
Self: Sized,
B: Default + Extend<Self::Item>,
F: FnMut(&Self::Item) -> bool,is_partitioned
检查此迭代器的元素是否根据给定的谓词进行了分区,以便所有返回 true 的元素都在所有返回 false 的元素之前。
fn is_partitioned<P>(self, predicate: P) -> bool
where
Self: Sized,
P: FnMut(Self::Item) -> bool,try_fold
一个迭代器方法,它只要成功返回就应用函数,并产生单个最终值。
fn try_fold<B, F, R>(&mut self, init: B, f: F) -> R
where
Self: Sized,
F: FnMut(B, Self::Item) -> R,
R: Try<Output = B>,try_for_each
一个迭代器方法,该方法将一个容易犯错的函数应用于迭代器中的每个项,在第一个错误处停止并返回该错误。
fn try_for_each<F, R>(&mut self, f: F) -> R
where
Self: Sized,
F: FnMut(Self::Item) -> R,
R: Try<Output = ()>,fold
通过应用操作将每个元素 fold 到一个累加器中,返回最终结果。
fn fold<B, F>(self, init: B, f: F) -> B
where
Self: Sized,
F: FnMut(B, Self::Item) -> B,reduce
通过重复应用缩减操作,将元素缩减为一个。
fn reduce<F>(self, f: F) -> Option<Self::Item>
where
Self: Sized,
F: FnMut(Self::Item, Self::Item) -> Self::Item,try_reduce
通过重复应用 Reduce 操作,将元素归约为单个元素。 如果闭包返回失败,则失败会立即传播给调用者。
fn try_reduce<F, R>(
&mut self,
f: F
) -> <<R as Try>::Residual as Residual<Option<<R as Try>::Output>>>::TryType
where
Self: Sized,
F: FnMut(Self::Item, Self::Item) -> R,
R: Try<Output = Self::Item>,
<R as Try>::Residual: Residual<Option<Self::Item>>,all
测试迭代器的每个元素是否与谓词匹配。
fn all<F>(&mut self, f: F) -> bool
where
Self: Sized,
F: FnMut(Self::Item) -> bool,any
测试迭代器的任何元素是否与谓词匹配。
fn any<F>(&mut self, f: F) -> bool
where
Self: Sized,
F: FnMut(Self::Item) -> bool,find
搜索满足谓词的迭代器的元素。
fn find<P>(&mut self, predicate: P) -> Option<Self::Item>
where
Self: Sized,
P: FnMut(&Self::Item) -> bool,find_map
将函数应用于迭代器的元素,并返回第一个非 None 的结果。
fn find_map<B, F>(&mut self, f: F) -> Option<B>
where
Self: Sized,
F: FnMut(Self::Item) -> Option<B>,try_find
将函数应用于迭代器的元素,并返回第一个为 true 的结果或第一个错误。
fn try_find<F, R>(
&mut self,
f: F
) -> <<R as Try>::Residual as Residual<Option<Self::Item>>>::TryType
where
Self: Sized,
F: FnMut(&Self::Item) -> R,
R: Try<Output = bool>,
<R as Try>::Residual: Residual<Option<Self::Item>>,position
在迭代器中搜索元素,并返回其索引。
fn position<P>(&mut self, predicate: P) -> Option<usize>
where
Self: Sized,
P: FnMut(Self::Item) -> bool,max_by_key
返回给出指定函数最大值的元素。
fn max_by_key<B, F>(self, f: F) -> Option<Self::Item>
where
B: Ord,
Self: Sized,
F: FnMut(&Self::Item) -> B,max_by
返回给出相对于指定比较函数的最大值的元素。
fn max_by<F>(self, compare: F) -> Option<Self::Item>
where
Self: Sized,
F: FnMut(&Self::Item, &Self::Item) -> Ordering,min_by_key
返回给出指定函数中最小值的元素。
fn min_by_key<B, F>(self, f: F) -> Option<Self::Item>
where
B: Ord,
Self: Sized,
F: FnMut(&Self::Item) -> B,min_by
返回给出相对于指定比较函数的最小值的元素。
fn min_by<F>(self, compare: F) -> Option<Self::Item>
where
Self: Sized,
F: FnMut(&Self::Item, &Self::Item) -> Ordering,unzip
将成对的迭代器转换为一对容器。
fn unzip<A, B, FromA, FromB>(self) -> (FromA, FromB)
where
FromA: Default + Extend<A>,
FromB: Default + Extend<B>,
Self: Sized + Iterator<Item = (A, B)>,copied
创建一个迭代器,该迭代器将复制其所有元素。
fn copied<'a, T>(self) -> Copied<Self>
where
T: 'a + Copy,
Self: Sized + Iterator<Item = &'a T>,cloned
创建一个迭代器,该迭代器将克隆所有元素。
fn cloned<'a, T>(self) -> Cloned<Self>
where
T: 'a + Clone,
Self: Sized + Iterator<Item = &'a T>,array_chunks
一次返回迭代器的 N 个元素的迭代器。
fn array_chunks<const N: usize>(self) -> ArrayChunks<Self, N>
where
Self: Sized,sum
对迭代器的元素求和。
fn sum<S>(self) -> S
where
Self: Sized,
S: Sum<Self::Item>,product
遍历整个迭代器,将所有元素相乘
fn product<P>(self) -> P
where
Self: Sized,
P: Product<Self::Item>,cmp_by
字典顺序 根据指定的比较函数将这个 Iterator 的元素与另一个 Iterator 的元素进行比较。
fn cmp_by<I, F>(self, other: I, cmp: F) -> Ordering
where
Self: Sized,
I: IntoIterator,
F: FnMut(Self::Item, <I as IntoIterator>::Item) -> Ordering,partial_cmp
Lexicographically 将此 Iterator 的 PartialOrd 元素与另一个 PartialOrd 的元素进行比较。 比较的工作方式类似于短路评估,返回结果而不比较其余元素。 一旦可以确定订单,评估就会停止并返回结果。
fn partial_cmp<I>(self, other: I) -> Option<Ordering>
where
I: IntoIterator,
Self::Item: PartialOrd<<I as IntoIterator>::Item>,
Self: Sized,partial_cmp_by
字典顺序 根据指定的比较函数将这个 Iterator 的元素与另一个 Iterator 的元素进行比较。
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>,eq
确定此 Iterator 的元素是否与另一个元素相同。
fn eq<I>(self, other: I) -> bool
where
I: IntoIterator,
Self::Item: PartialEq<<I as IntoIterator>::Item>,
Self: Sized,eq_by
关于指定的相等函数,确定 Iterator 的元素是否与另一个元素相等。
fn eq_by<I, F>(self, other: I, eq: F) -> bool
where
Self: Sized,
I: IntoIterator,
F: FnMut(Self::Item, <I as IntoIterator>::Item) -> bool,ne
确定此 Iterator 的元素是否不等于另一个的元素。
fn ne<I>(self, other: I) -> bool
where
I: IntoIterator,
Self::Item: PartialEq<<I as IntoIterator>::Item>,
Self: Sized,lt
确定此 Iterator 的元素是否比另一个元素少 按字典顺序。
fn lt<I>(self, other: I) -> bool
where
I: IntoIterator,
Self::Item: PartialOrd<<I as IntoIterator>::Item>,
Self: Sized,le
确定此 Iterator 的元素是否 按字典顺序 小于或等于另一个元素。
fn le<I>(self, other: I) -> bool
where
I: IntoIterator,
Self::Item: PartialOrd<<I as IntoIterator>::Item>,
Self: Sized,gt
确定此 Iterator 的元素是否大于另一个元素的 按字典顺序。
fn gt<I>(self, other: I) -> bool
where
I: IntoIterator,
Self::Item: PartialOrd<<I as IntoIterator>::Item>,
Self: Sized,ge
确定此 Iterator 的元素是否 按字典顺序 大于或等于另一个元素。
fn ge<I>(self, other: I) -> bool
where
I: IntoIterator,
Self::Item: PartialOrd<<I as IntoIterator>::Item>,
Self: Sized,is_sorted_by
检查此迭代器的元素是否使用给定的比较器函数进行排序。
fn is_sorted_by<F>(self, compare: F) -> bool
where
Self: Sized,
F: FnMut(&Self::Item, &Self::Item) -> Option<Ordering>,is_sorted_by_key
检查此迭代器的元素是否使用给定的键提取函数进行排序。
fn is_sorted_by_key<F, K>(self, f: F) -> bool
where
Self: Sized,
F: FnMut(Self::Item) -> K,
K: PartialOrd<K>,Auto Trait Implementations
impl<B> RefUnwindSafe for Lines<B>
impl<B> RefUnwindSafe for Lines<B>
where
B: RefUnwindSafe,impl<B> Send for Lines<B>
impl<B> Send for Lines<B>
where
B: Send,impl<B> Sync for Lines<B>
impl<B> Sync for Lines<B>
where
B: Sync,impl<B> Unpin for Lines<B>
impl<B> Unpin for Lines<B>
where
B: Unpin,impl<B> UnwindSafe for Lines<B>
impl<B> UnwindSafe for Lines<B>
where
B: UnwindSafe,Blanket Implementations
impl<T> Any for T
impl<T> Any for T
where
T: 'static + ?Sized,impl<T> Borrow<T> for T
impl<T> Borrow<T> for T
where
T: ?Sized,impl<T> BorrowMut<T> for T
impl<T> BorrowMut<T> for T
where
T: ?Sized,impl<T> From<T> for T
impl<T, U> Into<U> for T
impl<T, U> Into<U> for T
where
U: From<T>,impl<I> IntoIterator for I
impl<I> IntoIterator for I
where
I: Iterator,impl<T, U> TryFrom<U> for T
impl<T, U> TryFrom<U> for T
where
U: Into<T>,impl<T, U> TryInto<U> for T
impl<T, U> TryInto<U> for T
where
U: TryFrom<T>,