aboutsummaryrefslogtreecommitdiff
path: root/src/model/user.rs
diff options
context:
space:
mode:
authorZeyla Hellyer <[email protected]>2017-05-04 12:54:58 -0700
committerZeyla Hellyer <[email protected]>2017-05-04 12:54:58 -0700
commit4cdaf3a3187125971bdc9e5c5e52b36d70f563c2 (patch)
treeba4ee4bf1d9d6f9c3a8122c5ee99657c26ddd99b /src/model/user.rs
parentAdd missing Member::kick shortcut (diff)
downloadserenity-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.rs21
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)