libcore: Add from_buf_len_nocopy

This commit is contained in:
Patrick Walton 2012-08-22 17:03:57 -07:00
parent dcbeebc801
commit 83e7c869bd

View File

@ -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))