Skip to content

Instantly share code, notes, and snippets.

View FuuuOverclocking's full-sized avatar
🏠
Working from home

Fuu FuuuOverclocking

🏠
Working from home
View GitHub Profile
@FuuuOverclocking
FuuuOverclocking / consume_vec_in_order.rs
Created February 2, 2023 03:36
[Rust] Traverse and consume the vector in the given order
use std::mem::{self, ManuallyDrop};
use std::ptr;
/// Traverse the vector in the given order. The vector will be consumed, and its
/// elements will be moved in when calling the closure. `order` must contain all
/// values in the range `0..vec.len()` without repetition or omission, but the
/// order of elements can be arbitrary.
///
/// # Example
/// ```