File tree Expand file tree Collapse file tree 1 file changed +8
-0
lines changed Expand file tree Collapse file tree 1 file changed +8
-0
lines changed Original file line number Diff line number Diff line change @@ -1768,6 +1768,7 @@ mod unsafe {
1768
1768
export
1769
1769
from_buf,
1770
1770
from_buf_len,
1771
+ from_buf_len_nocopy,
1771
1772
from_c_str,
1772
1773
from_c_str_len,
1773
1774
from_bytes,
@@ -1799,6 +1800,13 @@ mod unsafe {
1799
1800
return :: unsafe:: transmute ( v) ;
1800
1801
}
1801
1802
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
+
1802
1810
/// Create a Rust string from a null-terminated C string
1803
1811
unsafe fn from_c_str ( c_str : * libc:: c_char ) -> ~str {
1804
1812
from_buf ( :: unsafe:: reinterpret_cast ( c_str) )
You can’t perform that action at this time.
0 commit comments