Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use AsRef in debug API to be more flexible #77

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ mod native {
}

/// Prints a string.
pub fn log(msg: &str) {
pub fn log<T: AsRef<str>>(msg: T) {
let msg = msg.as_ref();
unsafe { native::debug_printMem(msg.as_ptr() as *const u32, msg.len() as u32) }
}

Expand All @@ -31,12 +32,14 @@ pub fn print64(value: u64) {
}

/// Prints the contents of a slice.
pub fn print_mem(slice: &[u8]) {
pub fn print_mem<T: AsRef<[u8]>>(slice: T) {
let slice = slice.as_ref();
unsafe { native::debug_printMem(slice.as_ptr() as *const u32, slice.len() as u32) }
}

/// Prints the contents of a slice in hexadecimal format.
pub fn print_mem_hex(slice: &[u8]) {
pub fn print_mem_hex<T: AsRef<[u8]>>(slice: T) {
let slice = slice.as_ref();
unsafe { native::debug_printMemHex(slice.as_ptr() as *const u32, slice.len() as u32) }
}

Expand Down