Add Show impls

This commit is contained in:
Steven Fackler 2015-01-09 20:17:47 -08:00
parent 5a153e9ead
commit 2f5d1e579b
1 changed files with 24 additions and 3 deletions

View File

@ -2,6 +2,7 @@ use libc::{c_int, c_void, c_long};
use std::ffi::{CString, c_str_to_bytes}; use std::ffi::{CString, c_str_to_bytes};
use std::io::{IoResult, IoError, EndOfFile, Stream, Reader, Writer}; use std::io::{IoResult, IoError, EndOfFile, Stream, Reader, Writer};
use std::mem; use std::mem;
use std::fmt;
use std::num::FromPrimitive; use std::num::FromPrimitive;
use std::ptr; use std::ptr;
use std::sync::{Once, ONCE_INIT, Arc}; use std::sync::{Once, ONCE_INIT, Arc};
@ -33,9 +34,8 @@ fn init() {
} }
/// Determines the SSL method supported /// Determines the SSL method supported
#[derive(Show, Hash, PartialEq, Eq)]
#[allow(non_camel_case_types)] #[allow(non_camel_case_types)]
#[derive(Copy)] #[derive(Copy, Clone, Show, Hash, PartialEq, Eq)]
pub enum SslMethod { pub enum SslMethod {
#[cfg(feature = "sslv2")] #[cfg(feature = "sslv2")]
/// Only support the SSLv2 protocol, requires `feature="sslv2"` /// Only support the SSLv2 protocol, requires `feature="sslv2"`
@ -71,7 +71,7 @@ impl SslMethod {
} }
/// Determines the type of certificate verification used /// Determines the type of certificate verification used
#[derive(Copy)] #[derive(Copy, Clone, Show)]
#[repr(i32)] #[repr(i32)]
pub enum SslVerifyMode { pub enum SslVerifyMode {
/// Verify that the server's certificate is trusted /// Verify that the server's certificate is trusted
@ -177,6 +177,13 @@ pub struct SslContext {
ctx: ptr::Unique<ffi::SSL_CTX> ctx: ptr::Unique<ffi::SSL_CTX>
} }
// TODO: add useful info here
impl fmt::Show for SslContext {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
write!(fmt, "SslContext")
}
}
impl Drop for SslContext { impl Drop for SslContext {
fn drop(&mut self) { fn drop(&mut self) {
unsafe { ffi::SSL_CTX_free(self.ctx.0) } unsafe { ffi::SSL_CTX_free(self.ctx.0) }
@ -293,6 +300,13 @@ pub struct Ssl {
ssl: ptr::Unique<ffi::SSL> ssl: ptr::Unique<ffi::SSL>
} }
// TODO: put useful information here
impl fmt::Show for Ssl {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
write!(fmt, "Ssl")
}
}
impl Drop for Ssl { impl Drop for Ssl {
fn drop(&mut self) { fn drop(&mut self) {
unsafe { ffi::SSL_free(self.ssl.0) } unsafe { ffi::SSL_free(self.ssl.0) }
@ -412,6 +426,12 @@ pub struct SslStream<S> {
buf: Vec<u8> buf: Vec<u8>
} }
impl<S> fmt::Show for SslStream<S> where S: fmt::Show {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
write!(fmt, "SslStream {{ stream: {:?}, ssl: {:?} }}", self.stream, self.ssl)
}
}
impl<S: Stream> SslStream<S> { impl<S: Stream> SslStream<S> {
fn new_base(ssl:Ssl, stream: S) -> SslStream<S> { fn new_base(ssl:Ssl, stream: S) -> SslStream<S> {
SslStream { SslStream {
@ -567,6 +587,7 @@ impl<S: Stream> Writer for SslStream<S> {
} }
/// A utility type to help in cases where the use of SSL is decided at runtime. /// A utility type to help in cases where the use of SSL is decided at runtime.
#[derive(Show)]
pub enum MaybeSslStream<S> where S: Stream { pub enum MaybeSslStream<S> where S: Stream {
/// A connection using SSL /// A connection using SSL
Ssl(SslStream<S>), Ssl(SslStream<S>),