Guest User

Untitled

a guest
Aug 25th, 2019
64
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. fn do_something<T, S>(params: &[S], subs: &[T])
  2. where
  3. T: Clone + std::slice::SliceIndex<[S]>,
  4. <T as std::slice::SliceIndex<[S]>>::Output: std::fmt::Debug,
  5. S: std::fmt::Debug,
  6. {
  7. for range in subs {
  8. println!("Sequence: {:?}", &params[range.clone()]);
  9. }
  10. println!("Unsliced: {:?}", params);
  11. }
  12.  
  13. fn main() {
  14. let mut params = vec![];
  15. let mut idx = vec![];
  16. let mut global_idx = 0;
  17. for seq in &[vec![0], vec![4, 3], vec![38, 2, 1, 255, 100]] {
  18. let start = global_idx;
  19. for p in seq {
  20. params.push(*p);
  21. global_idx += 1;
  22. }
  23. idx.push(start..global_idx);
  24. }
  25. do_something(&params, &idx);
  26. }
RAW Paste Data