Created
October 18, 2019 00:51
-
-
Save rust-play/f55ee0ddc318f1b263e4c7a51d2ced92 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
const NAME: &[u8] = b"abcde"; | |
fn main() { | |
// just setting up an example value. | |
let mut extension_name: [u8; 256] = unsafe { core::mem::zeroed() }; | |
extension_name[..5].copy_from_slice(NAME); | |
let name: String = String::from_utf8_lossy( | |
&extension_name | |
.iter() | |
.copied() | |
.map(|cc| cc as u8) | |
.take_while(|&u| u != 0_u8) | |
.collect::<Vec<u8>>() | |
).into_owned(); | |
println!("Name is: {}", name); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment