Function vibha::ffi_recover_str [] [src]

pub unsafe fn ffi_recover_str<'a>(
    ptr_ref: &'a *const u8,
    len: usize
) -> Cow<'a, str>

Converts the const pointer and len for the user's input line into a rusty form.

This accepts a reference to a const pointer so that the lifetime of the Cow value can be properly tracked. This way you can't make the Cow accidentally outlive the pointer it was built from.

extern crate vibha;
use vibha::ffi_recover_str;

let static_str = "demo";
let ptr_ref = &static_str.as_ptr();
let len = static_str.len();
let recovered_value = unsafe { ffi_recover_str(ptr_ref, len) };
assert_eq!(static_str, recovered_value);