about summary refs log tree commit diff
path: root/src/rustllvm/ExecutionEngineWrapper.cpp
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2015-05-23 11:12:02 +0000
committerbors <bors@rust-lang.org>2015-05-23 11:12:02 +0000
commit4c2ebc3947568f5ca11c4e8a97538296b4f78285 (patch)
tree63e1f3a8bdb342abacb432405355deefe586b555 /src/rustllvm/ExecutionEngineWrapper.cpp
parent8bc80ba9fc8a297e0633a4f6e7fad1c333cbe8b4 (diff)
parentd0b5eb35a26a92b3845e90ac340a6422893c447b (diff)
downloadrust-4c2ebc3947568f5ca11c4e8a97538296b4f78285.tar.gz
rust-4c2ebc3947568f5ca11c4e8a97538296b4f78285.zip
Auto merge of #25416 - kballard:ffi-cstr-to-str-convenience, r=alexcrichton
This was motivated by http://www.evanmiller.org/a-taste-of-rust.html.

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