diff options
| author | Zeyla Hellyer <[email protected]> | 2017-04-25 15:48:13 -0700 |
|---|---|---|
| committer | Zeyla Hellyer <[email protected]> | 2017-04-25 15:48:13 -0700 |
| commit | 0f41ffc811827fdd45e4e631884909e33fa8769e (patch) | |
| tree | 40c6d5091097ee86ed72e9868f77350bdaed078a /src/model/user.rs | |
| parent | Fix decoding for `CurrentUser.discriminator` (diff) | |
| download | serenity-0f41ffc811827fdd45e4e631884909e33fa8769e.tar.xz serenity-0f41ffc811827fdd45e4e631884909e33fa8769e.zip | |
Make `User.discriminator` a u16
Change the User struct's `discriminator` field to a u16 for performance.
The User struct's `discriminator` field was previously a u16 but changed
to a `String` for ease-of-use. Lately the library has been gearing more
towards performance where possible while not sacrificing ergonomics
_too much_ in most scenarios.
Diffstat (limited to 'src/model/user.rs')
| -rw-r--r-- | src/model/user.rs | 19 |
1 files changed, 4 insertions, 15 deletions
diff --git a/src/model/user.rs b/src/model/user.rs index 686d394..040effa 100644 --- a/src/model/user.rs +++ b/src/model/user.rs @@ -318,7 +318,8 @@ pub struct User { /// the same [`name`]. The name+discriminator pair is always unique. /// /// [`name`]: #structfield.name - pub discriminator: String, + #[serde(deserialize_with="deserialize_u16")] + pub discriminator: u16, /// The account's username. Changing username will trigger a discriminator /// change if the username+discriminator pair becomes non-unique. #[serde(rename="username")] @@ -366,20 +367,8 @@ impl User { /// Returns the formatted URL to the user's default avatar URL. /// /// This will produce a PNG URL. - /// - /// # Errors - /// - /// Returns an [`Error::Num`] if there was an error parsing the - /// discriminator. Theoretically this is not possible. - /// - /// Returns an [`Error::Other`] if the remainder of the calculation - /// `discriminator % 5` can not be matched. This is also probably not going - /// to occur. - /// - /// [`Error::Num`]: ../enum.Error.html#variant.Num - /// [`Error::Other`]: ../enum.Error.html#variant.Other - pub fn default_avatar_url(&self) -> Result<String> { - Ok(cdn!("/embed/avatars/{}.png", self.discriminator.parse::<u16>()? % 5u16).to_owned()) + pub fn default_avatar_url(&self) -> String { + cdn!("/embed/avatars/{}.png", self.discriminator % 5u16).to_owned() } /// Sends a message to a user through a direct message channel. This is a |