Created
September 21, 2018 19:01
-
-
Save rust-play/3744c32e7e3fa1ef56fdc9f2b02d49b9 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
#[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