blob: fa2402938f183e39570f065d976ec3280124ad98 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
use std::{
ffi,
str,
};
use libc;
pub trait NewFromPtr<T> {
fn new(ptr: T) -> Self;
}
pub trait ToStr {
fn to_str<'a>(&self) -> Result<&'a str, str::Utf8Error>;
}
impl ToStr for *const libc::c_char {
fn to_str<'a>(&self) -> Result<&'a str, str::Utf8Error> {
str::from_utf8(unsafe {
ffi::CStr::from_ptr(*self)
}.to_bytes())
}
}
|