about summary refs log tree commit diff
path: root/src/rustllvm/ExecutionEngineWrapper.cpp
diff options
context:
space:
mode:
authorKevin Ballard <kevin@sb.org>2015-05-14 14:49:32 -0700
committerKevin Ballard <kevin@sb.org>2015-05-22 11:46:46 -0700
commitd0b5eb35a26a92b3845e90ac340a6422893c447b (patch)
tree3faf026dc95d65c25e12b1e3e23ee6c226284396 /src/rustllvm/ExecutionEngineWrapper.cpp
parentdd4dad8c860363077a3d53af025a0c029a613320 (diff)
downloadrust-d0b5eb35a26a92b3845e90ac340a6422893c447b.tar.gz
rust-d0b5eb35a26a92b3845e90ac340a6422893c447b.zip
Add some convenience methods to go from CStr -> str
A common problem when working with FFI right now is converting from raw
C strings into `&str` or `String`. Right now you're required to say
something like

    let cstr = unsafe { CStr::from_ptr(ptr) };
    let result = str::from_utf8(cstr.to_bytes());

This is slightly awkward, and is not particularly intuitive for people
who haven't used the ffi module before. We can do a bit better by
providing some convenience methods on CStr:

    fn to_str(&self) -> Result<&str, str::Utf8Error>
    fn to_string_lossy(&self) -> Cow<str>

This will make it immediately apparent to new users of CStr how to get a
string from a raw C string, so they can say:

    let s = unsafe { CStr::from_ptr(ptr).to_string_lossy() };
Diffstat (limited to 'src/rustllvm/ExecutionEngineWrapper.cpp')
0 files changed, 0 insertions, 0 deletions