diff --git a/src/libcore/str.rs b/src/libcore/str.rs index 5f1c100a155..ec61ace2f13 100644 --- a/src/libcore/str.rs +++ b/src/libcore/str.rs @@ -1768,6 +1768,7 @@ mod unsafe { export from_buf, from_buf_len, + from_buf_len_nocopy, from_c_str, from_c_str_len, from_bytes, @@ -1799,6 +1800,13 @@ mod unsafe { return ::unsafe::transmute(v); } + /// Create a Rust string from a *u8 buffer of the given length without copying + unsafe fn from_buf_len_nocopy(buf: &a / *u8, len: uint) -> &a / str { + let v = (*buf, len + 1); + assert is_utf8(::unsafe::reinterpret_cast(v)); + return ::unsafe::transmute(v); + } + /// Create a Rust string from a null-terminated C string unsafe fn from_c_str(c_str: *libc::c_char) -> ~str { from_buf(::unsafe::reinterpret_cast(c_str))