Browse Source

Add `ptr_to_string` function

Converts a raw C char pointer to an owned Rust string.
fixes
Andreas Linz 5 years ago
parent
commit
591a000393
1 changed files with 8 additions and 0 deletions
  1. +8
    -0
      src/ffi.rs

+ 8
- 0
src/ffi.rs View File

@ -1,6 +1,14 @@
// automatically generated by rust-bindgen
use std::os::raw::{c_char, c_int};
use std::str::Utf8Error;
use std::ffi::CStr;
use std::ffi::CString;
fn ptr_to_string(str_ptr: *const c_char) -> Result<String, Utf8Error> {
let str_slice: &str = try!(unsafe { CStr::from_ptr(str_ptr) }.to_str());
Ok(str_slice.to_string())
}
#[derive(Clone, Copy, Debug, PartialEq)]
#[repr(u32)]

Loading…
Cancel
Save