Skip to content

Commit

Permalink
Implement From<&str> for ReactionType
Browse files Browse the repository at this point in the history
Implement the ability to create a ReactionType from a string slice.

This is to be able to produce code like:

```rust
msg.react("🍎");
```

rather than needing to go the longer route:

```rust
msg.react("🍎".to_owned());
```
  • Loading branch information
Zeyla Hellyer committed Apr 19, 2017
1 parent 3f03f9a commit e7110ad
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/model/channel/reaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,28 @@ impl From<String> for ReactionType {
}
}

impl<'a> From<&'a str> for ReactionType {
/// Creates a `ReactionType` from a string slice.
///
/// # Examples
///
/// Creating a `ReactionType` from a `🍎`, modeling a similar API as the
/// rest of the library:
///
/// ```rust
/// use serenity::model::ReactionType;
///
/// fn foo<R: Into<ReactionType>>(bar: R) {
/// println!("{:?}", bar.into());
/// }
///
/// foo("🍎");
/// ```
fn from(unicode: &str) -> ReactionType {
ReactionType::Unicode(unicode.to_owned())
}
}

impl Display for ReactionType {
/// Formats the reaction type, displaying the associated emoji in a
/// way that clients can understand.
Expand Down

0 comments on commit e7110ad

Please sign in to comment.