Skip to content

Instantly share code, notes, and snippets.

@rust-play
Created September 21, 2018 19:01
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/3744c32e7e3fa1ef56fdc9f2b02d49b9 to your computer and use it in GitHub Desktop.
Save rust-play/3744c32e7e3fa1ef56fdc9f2b02d49b9 to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
#[no_mangle]
pub fn write(message: &str, color: u8, len: u8, slice: &mut [u8]) {
let bytes = message.bytes().take(len as usize);
let mut out = slice.iter_mut();
bytes.for_each(|byte| {
*out.next().unwrap() = byte;
*out.next().unwrap() = color;
})
}
fn main() {
let mut slice = [0; 30];
write("hello world", 0x02, 10, &mut slice[..]);
println!("{:?}", slice)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment