aboutsummaryrefslogtreecommitdiff
path: root/src/utils/colour.rs
diff options
context:
space:
mode:
authorAustin Hellyer <[email protected]>2016-11-14 22:06:54 -0800
committerAustin Hellyer <[email protected]>2016-11-14 22:06:54 -0800
commit83e57f9191c44104addc56537a5fb534b0c4382f (patch)
treef845841ae811c75486a04425bb31ccbaf2632183 /src/utils/colour.rs
parentAllow current user to nickname themselves (diff)
downloadserenity-83e57f9191c44104addc56537a5fb534b0c4382f.tar.xz
serenity-83e57f9191c44104addc56537a5fb534b0c4382f.zip
Decode embed/role colours into Colour struct
This is for a little bit of ergonomics, and is of such a minute cost that it is worth it to just directly decode the u32's received for Role/Embed colours into the Colour struct.
Diffstat (limited to 'src/utils/colour.rs')
-rw-r--r--src/utils/colour.rs11
1 files changed, 11 insertions, 0 deletions
diff --git a/src/utils/colour.rs b/src/utils/colour.rs
index b9a3bf5..e2c70e6 100644
--- a/src/utils/colour.rs
+++ b/src/utils/colour.rs
@@ -1,4 +1,5 @@
use std::default::Default;
+use ::internal::prelude::*;
macro_rules! colour {
($struct_:ident; $($name:ident, $val:expr;)*) => {
@@ -49,6 +50,7 @@ macro_rules! colour {
/// [`Role`]: ../model/struct.Role.html
/// [`dark_teal`]: #method.dark_teal
/// [`get_g`]: #method.get_g
+#[derive(Clone, Copy, Debug)]
pub struct Colour {
/// The raw inner integer value of this Colour. This is worked with to
/// generate values such as the red component value.
@@ -63,6 +65,15 @@ impl Colour {
}
}
+ #[doc(hidden)]
+ pub fn decode(value: Value) -> Result<Colour> {
+ match value {
+ Value::U64(v) => Ok(Colour::new(v as u32)),
+ Value::I64(v) => Ok(Colour::new(v as u32)),
+ other => Err(Error::Decode("Expected valid colour", other)),
+ }
+ }
+
/// Returns the red RGB component of this Colour.
pub fn get_r(&self) -> u8 {
((self.value >> 16) & 255) as u8