Trait CStrExt

Source
pub trait CStrExt {
    // Required method
    fn as_string(&self) -> Result<String>;
}

Required Methods§

Source

fn as_string(&self) -> Result<String>

Convert a C-style string (E.g. char*) to a Rust String

Returns an io::Error if the string pointer is null or cannot be

Implementations on Foreign Types§

Source§

impl CStrExt for *const i8

Source§

fn as_string(&self) -> Result<String>

Copy a C-style *const i8 string to a String

use switchtec_user_sys::CStrExt;

let cstr = CString::new(*b"hello")?;
// This is a type you might receive from an extern "C" function:
let str_value: *const i8 = cstr.as_ptr() as *const i8;

let rust_string: String = str_value.as_string()?;
assert_eq!(&rust_string, "hello");
Source§

impl CStrExt for *mut i8

Source§

fn as_string(&self) -> Result<String>

Copy a C-style *mut i8 string to a String

use switchtec_user_sys::CStrExt;

let cstr = CString::new(*b"hello")?;
// This is a type you might receive from an extern "C" function:
let str_value: *mut i8 = cstr.as_ptr() as *mut i8;

let rust_string: String = str_value.as_string()?;
assert_eq!(&rust_string, "hello");

Implementors§