Rollup merge of #82917 - cuviper:iter-zip, r=m-ou-se
Add function core::iter::zip This makes it a little easier to `zip` iterators: ```rust for (x, y) in zip(xs, ys) {} // vs. for (x, y) in xs.into_iter().zip(ys) {} ``` You can `zip(&mut xs, &ys)` for the conventional `iter_mut()` and `iter()`, respectively. This can also support arbitrary nesting, where it's easier to see the item layout than with arbitrary `zip` chains: ```rust for ((x, y), z) in zip(zip(xs, ys), zs) {} for (x, (y, z)) in zip(xs, zip(ys, zs)) {} // vs. for ((x, y), z) in xs.into_iter().zip(ys).zip(xz) {} for (x, (y, z)) in xs.into_iter().zip((ys.into_iter().zip(xz)) {} ``` It may also format more nicely, especially when the first iterator is a longer chain of methods -- for example: ```rust iter::zip( trait_ref.substs.types().skip(1), impl_trait_ref.substs.types().skip(1), ) // vs. trait_ref .substs .types() .skip(1) .zip(impl_trait_ref.substs.types().skip(1)) ``` This replaces the tuple-pair `IntoIterator` in #78204. There is prior art for the utility of this in [`itertools::zip`]. [`itertools::zip`]: https://docs.rs/itertools/0.10.0/itertools/fn.zip.html
This commit is contained in:
commit
b2e254318d
111 changed files with 310 additions and 256 deletions
|
@ -2214,9 +2214,7 @@ pub fn is_case_difference(sm: &SourceMap, suggested: &str, sp: Span) -> bool {
|
|||
};
|
||||
let ascii_confusables = &['c', 'f', 'i', 'k', 'o', 's', 'u', 'v', 'w', 'x', 'y', 'z'];
|
||||
// All the chars that differ in capitalization are confusable (above):
|
||||
let confusable = found
|
||||
.chars()
|
||||
.zip(suggested.chars())
|
||||
let confusable = iter::zip(found.chars(), suggested.chars())
|
||||
.filter(|(f, s)| f != s)
|
||||
.all(|(f, s)| (ascii_confusables.contains(&f) || ascii_confusables.contains(&s)));
|
||||
confusable && found.to_lowercase() == suggested.to_lowercase()
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
#![feature(crate_visibility_modifier)]
|
||||
#![feature(backtrace)]
|
||||
#![feature(extended_key_value_attributes)]
|
||||
#![feature(iter_zip)]
|
||||
#![feature(nll)]
|
||||
|
||||
#[macro_use]
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
// Code for creating styled buffers
|
||||
|
||||
use crate::snippet::{Style, StyledString};
|
||||
use std::iter;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct StyledBuffer {
|
||||
|
@ -20,11 +21,11 @@ impl StyledBuffer {
|
|||
let mut output: Vec<Vec<StyledString>> = vec![];
|
||||
let mut styled_vec: Vec<StyledString> = vec![];
|
||||
|
||||
for (row, row_style) in self.text.iter().zip(&self.styles) {
|
||||
for (row, row_style) in iter::zip(&self.text, &self.styles) {
|
||||
let mut current_style = Style::NoStyle;
|
||||
let mut current_text = String::new();
|
||||
|
||||
for (&c, &s) in row.iter().zip(row_style) {
|
||||
for (&c, &s) in iter::zip(row, row_style) {
|
||||
if s != current_style {
|
||||
if !current_text.is_empty() {
|
||||
styled_vec.push(StyledString { text: current_text, style: current_style });
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue