diff options
| author | Zeyla Hellyer <[email protected]> | 2017-04-14 07:34:28 -0700 |
|---|---|---|
| committer | Zeyla Hellyer <[email protected]> | 2017-04-19 14:53:32 -0700 |
| commit | e7110adb1e5659b7395588381c2e56c2aa06d1fa (patch) | |
| tree | 8b9f90a5c1f3d11fd5ee2cf81b6d99caf770ccd8 /src | |
| parent | Deprecate methods prefixed with `get_` (diff) | |
| download | serenity-e7110adb1e5659b7395588381c2e56c2aa06d1fa.tar.xz serenity-e7110adb1e5659b7395588381c2e56c2aa06d1fa.zip | |
Implement `From<&str> for ReactionType`
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());
```
Diffstat (limited to 'src')
| -rw-r--r-- | src/model/channel/reaction.rs | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/model/channel/reaction.rs b/src/model/channel/reaction.rs index 3abe7b8..32f6aa8 100644 --- a/src/model/channel/reaction.rs +++ b/src/model/channel/reaction.rs @@ -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. |