libcore: Add from_buf_len_nocopy
This commit is contained in:
parent
dcbeebc801
commit
83e7c869bd
@ -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))
|
||||
|
Loading…
x
Reference in New Issue
Block a user