diff options
| author | Zeyla Hellyer <[email protected]> | 2017-05-04 12:54:58 -0700 |
|---|---|---|
| committer | Zeyla Hellyer <[email protected]> | 2017-05-04 12:54:58 -0700 |
| commit | 4cdaf3a3187125971bdc9e5c5e52b36d70f563c2 (patch) | |
| tree | ba4ee4bf1d9d6f9c3a8122c5ee99657c26ddd99b /src/model/user.rs | |
| parent | Add missing Member::kick shortcut (diff) | |
| download | serenity-4cdaf3a3187125971bdc9e5c5e52b36d70f563c2.tar.xz serenity-4cdaf3a3187125971bdc9e5c5e52b36d70f563c2.zip | |
Accept references on Into<Id>
By accepting references, users don't have to either pass in the entirity
of an instance or clone it.
Diffstat (limited to 'src/model/user.rs')
| -rw-r--r-- | src/model/user.rs | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/src/model/user.rs b/src/model/user.rs index 040effa..8e38c44 100644 --- a/src/model/user.rs +++ b/src/model/user.rs @@ -604,6 +604,13 @@ impl From<CurrentUser> for UserId { } } +impl<'a> From<&'a CurrentUser> for UserId { + /// Gets the Id of a `CurrentUser` struct. + fn from(current_user: &CurrentUser) -> UserId { + current_user.id + } +} + impl From<Member> for UserId { /// Gets the Id of a `Member`. fn from(member: Member) -> UserId { @@ -611,6 +618,13 @@ impl From<Member> for UserId { } } +impl<'a> From<&'a Member> for UserId { + /// Gets the Id of a `Member`. + fn from(member: &Member) -> UserId { + member.user.read().unwrap().id + } +} + impl From<User> for UserId { /// Gets the Id of a `User`. fn from(user: User) -> UserId { @@ -618,6 +632,13 @@ impl From<User> for UserId { } } +impl<'a> From<&'a User> for UserId { + /// Gets the Id of a `User`. + fn from(user: &User) -> UserId { + user.id + } +} + impl fmt::Display for UserId { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fmt::Display::fmt(&self.0, f) |