You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As long as string slices expect to have an extra byte at the end this function cannot be expressed without copying. Here's how it's written:
1964- /// Form a slice from a *u8 buffer of the given length without copying.
1965: pub unsafe fn buf_as_slice<T>(buf: *u8, len: uint,
1966- f: fn(v: &str) -> T) -> T {
1967- let v = (buf, len + 1);
1968- assert is_utf8(::cast::reinterpret_cast(&v));
1969- f(::cast::transmute(move v))
1970- }
1971-
That extra byte in len + 1 is just random memory, which is_utf8 immediately reads.