diff options
Diffstat (limited to 'rust/src/string.rs')
| -rw-r--r-- | rust/src/string.rs | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/rust/src/string.rs b/rust/src/string.rs index 965d21f3..cff0fba7 100644 --- a/rust/src/string.rs +++ b/rust/src/string.rs @@ -261,16 +261,23 @@ unsafe impl BnStrCompatible for String { type Result = Vec<u8>; fn into_bytes_with_nul(self) -> Self::Result { - let ret = CString::new(self).expect("can't pass strings with internal nul bytes to core!"); - ret.into_bytes_with_nul() + self.as_str().into_bytes_with_nul() + } +} + +unsafe impl<'a> BnStrCompatible for &'a String { + type Result = Vec<u8>; + + fn into_bytes_with_nul(self) -> Self::Result { + self.as_str().into_bytes_with_nul() } } unsafe impl<'a> BnStrCompatible for &'a Cow<'a, str> { - type Result = &'a [u8]; + type Result = Vec<u8>; fn into_bytes_with_nul(self) -> Self::Result { - self.as_ref().as_bytes() + self.to_string().into_bytes_with_nul() } } |
