Skip to content

Commit 83e7c86

Browse files
committed
libcore: Add from_buf_len_nocopy
1 parent dcbeebc commit 83e7c86

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/libcore/str.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1768,6 +1768,7 @@ mod unsafe {
17681768
export
17691769
from_buf,
17701770
from_buf_len,
1771+
from_buf_len_nocopy,
17711772
from_c_str,
17721773
from_c_str_len,
17731774
from_bytes,
@@ -1799,6 +1800,13 @@ mod unsafe {
17991800
return ::unsafe::transmute(v);
18001801
}
18011802

1803+
/// Create a Rust string from a *u8 buffer of the given length without copying
1804+
unsafe fn from_buf_len_nocopy(buf: &a / *u8, len: uint) -> &a / str {
1805+
let v = (*buf, len + 1);
1806+
assert is_utf8(::unsafe::reinterpret_cast(v));
1807+
return ::unsafe::transmute(v);
1808+
}
1809+
18021810
/// Create a Rust string from a null-terminated C string
18031811
unsafe fn from_c_str(c_str: *libc::c_char) -> ~str {
18041812
from_buf(::unsafe::reinterpret_cast(c_str))

0 commit comments

Comments
 (0)