diff options
| author | Glenn Smith <glenn@vector35.com> | 2022-08-29 22:43:59 -0400 |
|---|---|---|
| committer | Glenn Smith <glenn@vector35.com> | 2022-09-29 21:02:22 -0400 |
| commit | 8cbdc0e05adefd58e6939f7bb70d6f031277e4f6 (patch) | |
| tree | 439ddd7a8eddaca0a54bb980f1ce8b46dc57399d /rust/src/string.rs | |
| parent | 9fd6ed156fb926c64420c1b38b4e27f0e5c17d0a (diff) | |
[Rust API]: Eq for Ref<Type>
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() } } |
