JesperAxelsson / rust-intmap

Specialized hashmap for u64 keys
MIT License
30 stars 12 forks source link

Leverage existing iterator adapters #33

Closed chinoto closed 2 years ago

JesperAxelsson commented 2 years ago

Didn't know you could IterSlices like that, neat!

chinoto commented 2 years ago

You can find out the type of a value by assigning it to a variable, supplying the wrong type, and cargo check will tell you what it found the type to actually be, such as let _: () = vec.iter().skip(5).take(5).cycle(); gives

error[E0308]: mismatched types
   --> src/lib.rs:432:21
    |
432 |         let _: () = vec.iter().skip(5).take(5).cycle();
    |                --   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `()`, found struct `Cycle`
    |                |
    |                expected due to this
    |
    = note: expected unit type `()`
                  found struct `Cycle<std::iter::Take<Skip<std::slice::Iter<'_, Vec<(K, V)>>>>>`

Then you just replace '_ with an explicit lifetime and it works.