From 565ee931137c3484710e0cc2613b1964d703016d Mon Sep 17 00:00:00 2001 From: Curtis McEnroe Date: Tue, 22 Dec 2015 00:59:58 -0500 Subject: [PATCH] Implement From<&str> for OAuth2ErrorCode --- src/error.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/error.rs b/src/error.rs index ef69f54..b7093fa 100644 --- a/src/error.rs +++ b/src/error.rs @@ -36,6 +36,20 @@ pub enum OAuth2ErrorCode { Unrecognized(String), } +impl<'a> From<&'a str> for OAuth2ErrorCode { + fn from(s: &str) -> OAuth2ErrorCode { + match s { + "invalid_request" => OAuth2ErrorCode::InvalidRequest, + "invalid_client" => OAuth2ErrorCode::InvalidClient, + "invalid_grant" => OAuth2ErrorCode::InvalidGrant, + "unauthorized_client" => OAuth2ErrorCode::UnauthorizedClient, + "unsupported_grant_type" => OAuth2ErrorCode::UnsupportedGrantType, + "invalid_scope" => OAuth2ErrorCode::InvalidScope, + s => OAuth2ErrorCode::Unrecognized(s.to_string()), + } + } +} + /// OAuth 2.0 error. /// /// See [RFC 6749, section 5.2](http://tools.ietf.org/html/rfc6749#section-5.2).