Advertisement
Guest User

Untitled

a guest
Oct 18th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. #[derive(Debug)] //just for printing
  2. struct Test {
  3. a: u32,
  4. b: u32,
  5. }
  6.  
  7. fn feed_me_slices(slice: &[Test]) {
  8. println!("Nom, nom! {:?} was tasty!", slice);
  9. }
  10.  
  11. fn main() {
  12. // Slices can be created just like that.
  13. // It's really a reference to an array,
  14. // but it gets coerced into a slice and
  15. // the length is no longer a part of the
  16. // type.
  17. //
  18. // The `: &[Test]` part is therefore not
  19. // really necessary here.
  20. let my_slice: &[Test] = &[
  21. Test { a: 1, b: 1},
  22. Test { a: 2, b: 2},
  23. Test { a: 3, b: 3},
  24. Test { a: 4, b: 4},
  25. ];
  26.  
  27. feed_me_slices(my_slice);
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement