From 850d02ddd1b2f8b8f33c308a28c7ec8059041b52 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Thu, 26 Sep 2019 00:36:55 +0100 Subject: [PATCH] Use AsRef in debug API to be more flexible --- src/debug.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/debug.rs b/src/debug.rs index a883ee7..17a687e 100644 --- a/src/debug.rs +++ b/src/debug.rs @@ -16,7 +16,8 @@ mod native { } /// Prints a string. -pub fn log(msg: &str) { +pub fn log>(msg: T) { + let msg = msg.as_ref(); unsafe { native::debug_printMem(msg.as_ptr() as *const u32, msg.len() as u32) } } @@ -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>(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>(slice: T) { + let slice = slice.as_ref(); unsafe { native::debug_printMemHex(slice.as_ptr() as *const u32, slice.len() as u32) } }