Add Error and Result types

This commit is contained in:
Curtis McEnroe 2015-11-28 13:21:41 -05:00
parent 85acefbb6d
commit 52f73b4836
3 changed files with 36 additions and 0 deletions

View File

@ -1,5 +1,7 @@
extern crate hyper;
extern crate inth_oauth2;
use std::io;
use inth_oauth2::Client;
fn main() {
@ -15,4 +17,9 @@ fn main() {
).unwrap();
println!("{}", auth_uri);
let mut code = String::new();
io::stdin().read_line(&mut code).unwrap();
client.request_access_token(hyper::Client::new(), &code).unwrap();
}

26
src/error.rs Normal file
View File

@ -0,0 +1,26 @@
use std::result;
use url;
use hyper;
/// Errors that can occur during authentication flow.
#[derive(Debug)]
pub enum Error {
Url(url::ParseError),
Hyper(hyper::Error),
}
/// Result type returned from authentication flow methods.
pub type Result<T> = result::Result<T, Error>;
impl From<url::ParseError> for Error {
fn from(err: url::ParseError) -> Error {
Error::Url(err)
}
}
impl From<hyper::Error> for Error {
fn from(err: hyper::Error) -> Error {
Error::Hyper(err)
}
}

View File

@ -7,3 +7,6 @@ mod client;
pub use token::Token;
mod token;
pub use error::{Error, Result};
mod error;