Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #[derive(Debug)] //just for printing
- struct Test {
- a: u32,
- b: u32,
- }
- fn feed_me_slices(slice: &[Test]) {
- println!("Nom, nom! {:?} was tasty!", slice);
- }
- fn main() {
- // Slices can be created just like that.
- // It's really a reference to an array,
- // but it gets coerced into a slice and
- // the length is no longer a part of the
- // type.
- //
- // The `: &[Test]` part is therefore not
- // really necessary here.
- let my_slice: &[Test] = &[
- Test { a: 1, b: 1},
- Test { a: 2, b: 2},
- Test { a: 3, b: 3},
- Test { a: 4, b: 4},
- ];
- feed_me_slices(my_slice);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement