Simplify cstr_from_bytes_with_nul_unchecked()

The original implementation is modified from the `Cstr` method, but the
complexity there exists because it is trying to convert to the DST `Cstr`.
This commit is contained in:
Ian Douglas Scott
2018-05-24 11:27:35 -07:00
parent 3311a700e0
commit 5bcf1d42ff
+1 -1
View File
@@ -55,7 +55,7 @@ pub unsafe fn c_str_n(s: *const c_char, n: usize) -> &'static [u8] {
}
pub unsafe fn cstr_from_bytes_with_nul_unchecked(bytes: &[u8]) -> *const c_char {
&*(bytes as *const [u8] as *const c_char)
bytes.as_ptr() as *const c_char
}
// NOTE: defined here rather than in string because memcpy() is useful in multiple crates