Created
October 18, 2019 00:26
-
-
Save rust-play/38c7db53b0ef217dbf905ccfea186126 to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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