Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is it useful to slice an entire array?

Tags:

arrays

rust

I found some code in an in-progress tutorial for Glium that seems to take a slice of an entire array:

use std::io::Cursor;
let image = image::load(Cursor::new(&include_bytes!("/path/to/image.png")[..]),
                        image::PNG).unwrap();

include_bytes! appears to load the given file into memory and then return a reference to it as a static array. What I'm confused about it why you would then take a reference to a slice of the entire array before passing it to Cursor::new.

like image 662
louis058 Avatar asked Dec 24 '22 14:12

louis058


1 Answers

include_bytes! produces something of type &[u8; N], so the &…[..] wrapping is to get a &[u8] out of it.

like image 178
Chris Morgan Avatar answered Dec 31 '22 01:12

Chris Morgan