Skip to content

Instantly share code, notes, and snippets.

@rust-play
Created October 18, 2019 00:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rust-play/38c7db53b0ef217dbf905ccfea186126 to your computer and use it in GitHub Desktop.
Save rust-play/38c7db53b0ef217dbf905ccfea186126 to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
fn cast_slice(slice: &[i8]) -> &[u8] {
unsafe { std::slice::from_raw_parts(slice.as_ptr().cast(), slice.len()) }
}
fn main() {
let array: [i8; 256] = [0; 256];
let slice: &[u8] = cast_slice(&array[..]);
println!("{:?}", slice);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment