Merge pull request #1038 from 1aim/string-asref

Implement AsRef<str/[u8]> for OpensslString{Ref}
This commit is contained in:
Steven Fackler 2019-01-17 09:04:49 -08:00 committed by GitHub
commit 79abbeaa81
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 26 additions and 1 deletions

View File

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