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 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 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)