Skip to content

Commit e3f5403

Browse files
committed
libcore: str::unsafe::from_buf_len_nocopy => form_slice
1 parent d0d68c6 commit e3f5403

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

src/libcore/str.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1967,10 +1967,10 @@ mod raw {
19671967
export
19681968
from_buf,
19691969
from_buf_len,
1970-
from_buf_len_nocopy,
19711970
from_c_str,
19721971
from_c_str_len,
19731972
from_bytes,
1973+
form_slice,
19741974
slice_bytes,
19751975
view_bytes,
19761976
push_byte,
@@ -2003,14 +2003,6 @@ mod raw {
20032003
return ::unsafe::transmute(move v);
20042004
}
20052005

2006-
/// Create a Rust string from a *u8 buffer of the given length
2007-
/// without copying
2008-
unsafe fn from_buf_len_nocopy(buf: &a / *u8, len: uint) -> &a / str {
2009-
let v = (*buf, len + 1);
2010-
assert is_utf8(::unsafe::reinterpret_cast(&v));
2011-
return ::unsafe::transmute(move v);
2012-
}
2013-
20142006
/// Create a Rust string from a null-terminated C string
20152007
unsafe fn from_c_str(c_str: *libc::c_char) -> ~str {
20162008
from_buf(::unsafe::reinterpret_cast(&c_str))
@@ -2031,6 +2023,13 @@ mod raw {
20312023
/// Converts a byte to a string.
20322024
unsafe fn from_byte(u: u8) -> ~str { raw::from_bytes([u]) }
20332025

2026+
/// Form a slice from a *u8 buffer of the given length without copying.
2027+
unsafe fn buf_as_slice<T>(buf: *u8, len: uint, f: fn(&& &str) -> T) -> T {
2028+
let v = (*buf, len + 1);
2029+
assert is_utf8(::unsafe::reinterpret_cast(&v));
2030+
f(::unsafe::transmute(move v))
2031+
}
2032+
20342033
/**
20352034
* Takes a bytewise (not UTF-8) slice from a string.
20362035
*

0 commit comments

Comments
 (0)