From 8cbdc0e05adefd58e6939f7bb70d6f031277e4f6 Mon Sep 17 00:00:00 2001 From: Glenn Smith Date: Mon, 29 Aug 2022 22:43:59 -0400 Subject: [Rust API]: Eq for Ref --- rust/src/string.rs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'rust/src/string.rs') 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; 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; + + 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; fn into_bytes_with_nul(self) -> Self::Result { - self.as_ref().as_bytes() + self.to_string().into_bytes_with_nul() } } -- cgit v1.3.1