You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
9 lines
277 B
9 lines
277 B
7 years ago
|
use core::fmt::Debug;
|
||
|
|
||
7 years ago
|
/// Convert C string to Rust string
|
||
|
pub unsafe fn from_cstr(s: *const u8) -> &'static str {
|
||
|
use core::{str, slice};
|
||
|
let len = (0usize..).find(|&i| *s.offset(i as isize) == 0).unwrap();
|
||
|
str::from_utf8(slice::from_raw_parts(s, len)).unwrap()
|
||
|
}
|