Skip to content

Instantly share code, notes, and snippets.

@rust-play
Created October 18, 2019 00:51
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/f55ee0ddc318f1b263e4c7a51d2ced92 to your computer and use it in GitHub Desktop.
Save rust-play/f55ee0ddc318f1b263e4c7a51d2ced92 to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
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