summaryrefslogtreecommitdiff
path: root/rust/src/string.rs
diff options
context:
space:
mode:
authorGlenn Smith <glenn@vector35.com>2022-08-29 22:43:59 -0400
committerGlenn Smith <glenn@vector35.com>2022-09-29 21:02:22 -0400
commit8cbdc0e05adefd58e6939f7bb70d6f031277e4f6 (patch)
tree439ddd7a8eddaca0a54bb980f1ce8b46dc57399d /rust/src/string.rs
parent9fd6ed156fb926c64420c1b38b4e27f0e5c17d0a (diff)
[Rust API]: Eq for Ref<Type>
Diffstat (limited to 'rust/src/string.rs')
-rw-r--r--rust/src/string.rs15
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()
}
}