summaryrefslogtreecommitdiff
path: root/openssl/src/string.rs
diff options
context:
space:
mode:
authorJonas Schievink <jonasschievink@gmail.com>2019-01-17 14:19:36 +0100
committerJonas Schievink <jonasschievink@gmail.com>2019-01-17 14:19:36 +0100
commitb565a0c7ebca3fd40b0c8d802d5e316ab385b4a9 (patch)
tree9e108262aaef24baae3f77e9529c478ade2557c8 /openssl/src/string.rs
parent69aa33587160e94e8c2f8eada36f6db18df60529 (diff)
downloadrust-openssl-b565a0c7ebca3fd40b0c8d802d5e316ab385b4a9.zip
Implement AsRef<str/[u8]> for OpensslString{Ref}
Diffstat (limited to 'openssl/src/string.rs')
-rw-r--r--openssl/src/string.rs27
1 files changed, 26 insertions, 1 deletions
diff --git a/openssl/src/string.rs b/openssl/src/string.rs
index 49d6d6f9..9796500a 100644
--- a/openssl/src/string.rs
+++ b/openssl/src/string.rs
@@ -1,8 +1,9 @@
use ffi;
use foreign_types::ForeignTypeRef;
use libc::{c_char, c_void};
-use std::fmt;
+use std::convert::AsRef;
use std::ffi::CStr;
+use std::fmt;
use std::ops::Deref;
use std::str;
@@ -32,6 +33,18 @@ impl Stackable for OpensslString {
type StackType = ffi::stack_st_OPENSSL_STRING;
}
+impl AsRef<str> for OpensslString {
+ fn as_ref(&self) -> &str {
+ &**self
+ }
+}
+
+impl AsRef<[u8]> for OpensslString {
+ fn as_ref(&self) -> &[u8] {
+ self.as_bytes()
+ }
+}
+
impl Deref for OpensslStringRef {
type Target = str;
@@ -43,6 +56,18 @@ impl Deref for OpensslStringRef {
}
}
+impl AsRef<str> for OpensslStringRef {
+ fn as_ref(&self) -> &str {
+ &*self
+ }
+}
+
+impl AsRef<[u8]> for OpensslStringRef {
+ fn as_ref(&self) -> &[u8] {
+ self.as_bytes()
+ }
+}
+
impl fmt::Display for OpensslStringRef {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fmt::Display::fmt(&**self, f)