mirror of
https://github.com/rust-lang/rust.git
synced 2026-04-27 18:57:42 +03:00
Fix SmallCStr conversion from CStr
This commit is contained in:
@@ -82,6 +82,6 @@ fn from_iter<T: IntoIterator<Item = &'a str>>(iter: T) -> Self {
|
||||
|
||||
impl From<&ffi::CStr> for SmallCStr {
|
||||
fn from(s: &ffi::CStr) -> Self {
|
||||
Self { data: SmallVec::from_slice(s.to_bytes()) }
|
||||
Self { data: SmallVec::from_slice(s.to_bytes_with_nul()) }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,3 +43,11 @@ fn long() {
|
||||
fn internal_nul() {
|
||||
let _ = SmallCStr::new("abcd\0def");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn from_cstr() {
|
||||
let c = c"foo";
|
||||
let s: SmallCStr = c.into();
|
||||
assert_eq!(s.len_with_nul(), 4);
|
||||
assert_eq!(s.as_c_str(), c"foo");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user