From 60532be947e0c5533fa35fae6a5f6851f11149a7 Mon Sep 17 00:00:00 2001 From: p0lunin Date: Wed, 1 Jan 2020 20:01:26 +0200 Subject: [PATCH] refactoring --- src/types/parse_mode.rs | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/src/types/parse_mode.rs b/src/types/parse_mode.rs index a7cbe566..aac3baca 100644 --- a/src/types/parse_mode.rs +++ b/src/types/parse_mode.rs @@ -2,9 +2,10 @@ // (for built ins there no warnings, but for (De)Serialize, there are) #![allow(deprecated)] -use std::{str::FromStr, convert::TryFrom} +use std::{str::FromStr, convert::TryFrom}; use serde::{Deserialize, Serialize}; +use std::convert::TryInto; /// ## Formatting options /// The Bot API supports basic formatting for messages. You can use bold, @@ -137,6 +138,7 @@ impl TryFrom<&str> for ParseMode { let normalized = value.to_lowercase(); match normalized.as_ref() { "html" => Ok(ParseMode::HTML), + #[allow(depredecated)] "markdown" => Ok(ParseMode::Markdown), _ => Err(()), } @@ -147,12 +149,7 @@ impl TryFrom for ParseMode { type Error = (); fn try_from(value: String) -> Result { - let normalized = value.to_lowercase(); - match normalized.as_ref() { - "html" => Ok(ParseMode::HTML), - "markdown" => Ok(ParseMode::Markdown), - _ => Err(()), - } + value.as_str().try_into() } } @@ -160,12 +157,7 @@ impl FromStr for ParseMode { type Err = (); fn from_str(s: &str) -> Result { - let normalized = s.to_lowercase(); - match normalized.as_ref() { - "html" => Ok(ParseMode::HTML), - "markdown" => Ok(ParseMode::Markdown), - _ => Err(()), - } + s.try_into() } }