Are there equivalents to slice::chunks/windows for iterators to loop over pairs, triplets etc?

It’s possible to take chunks of an iterator using Itertools::tuples, up to a 4-tuple: use itertools::Itertools; // 0.9.0 fn main() { let some_iter = vec![1, 2, 3, 4, 5, 6].into_iter(); for (prev, next) in some_iter.tuples() { println!(“{}–{}”, prev, next); } } (playground) 1–2 3–4 5–6 If you don’t know that your iterator exactly fits into … Read more

How do I create a Vec from a range and shuffle it?

Rand v0.6.0 The Rng::shuffle method is now deprecated; rand::seq::SliceRandom trait should be used. It provides the shuffle() method on all slices, which accepts an Rng instance: // Rust edition 2018 no longer needs extern crate use rand::thread_rng; use rand::seq::SliceRandom; fn main() { let mut vec: Vec<u32> = (0..10).collect(); vec.shuffle(&mut thread_rng()); println!(“{:?}”, vec); } See it … Read more

How to implement Iterator and IntoIterator for a simple struct?

Your iterator type is Iterator<Item = Self::Item>, but Iterator is a trait. Traits are implemented by structs, they don’t exist on their own. You could also have a reference trait object (&Iterator), a boxed trait object (Box<Iterator>) or an anonymous trait implementation (impl Iterator), all of which have a known sizes. Instead, we create a … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)