diff options
| author | acdenisSK <[email protected]> | 2017-11-04 23:12:17 +0100 |
|---|---|---|
| committer | acdenisSK <[email protected]> | 2017-11-04 23:12:17 +0100 |
| commit | 2032a402c387b1310f2ae62621f3e07c86b76aef (patch) | |
| tree | e34c35de1eb517d9b2469f02cd179ab9e6b34544 /src/model/channel | |
| parent | Merge v0.4.3 (diff) | |
| download | serenity-2032a402c387b1310f2ae62621f3e07c86b76aef.tar.xz serenity-2032a402c387b1310f2ae62621f3e07c86b76aef.zip | |
Whoops. Add a `FromStr` impl for `ReactionType`
Diffstat (limited to 'src/model/channel')
| -rw-r--r-- | src/model/channel/reaction.rs | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/model/channel/reaction.rs b/src/model/channel/reaction.rs index 1a40ecb..2003c28 100644 --- a/src/model/channel/reaction.rs +++ b/src/model/channel/reaction.rs @@ -1,5 +1,7 @@ use serde::de::{Deserialize, Error as DeError, MapAccess, Visitor}; use std::fmt::{Display, Formatter, Result as FmtResult, Write as FmtWrite}; +use std::str::FromStr; +use std::error::Error as StdError; use internal::prelude::*; use model::*; @@ -277,6 +279,31 @@ impl<'a> From<&'a str> for ReactionType { fn from(unicode: &str) -> ReactionType { ReactionType::Unicode(unicode.to_string()) } } +// TODO: Change this to `!` once it becomes stable. + +#[derive(Debug)] +pub struct NeverFails; + +impl Display for NeverFails { + fn fmt(&self, f: &mut Formatter) -> FmtResult { + write!(f, "never fails") + } +} + +impl StdError for NeverFails { + fn description(&self) -> &str { + "never fails" + } +} + +impl FromStr for ReactionType { + type Err = NeverFails; + + fn from_str(s: &str) -> ::std::result::Result<Self, Self::Err> { + Ok(ReactionType::from(s)) + } +} + impl Display for ReactionType { /// Formats the reaction type, displaying the associated emoji in a /// way that clients can understand. |