aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAustin Hellyer <[email protected]>2017-01-13 03:57:12 -0800
committerAustin Hellyer <[email protected]>2017-01-13 09:17:05 -0800
commita8acd6138741a6e5268141ac4ce902561931d353 (patch)
treef3cc01856d84bb34feca0695775b32208fb6ad9f /src
parentFix build (diff)
downloadserenity-a8acd6138741a6e5268141ac4ce902561931d353.tar.xz
serenity-a8acd6138741a6e5268141ac4ce902561931d353.zip
Convert Colour to be a tuple struct
The struct only has one field (`value`) anyway.
Diffstat (limited to 'src')
-rw-r--r--src/model/guild.rs2
-rw-r--r--src/utils/builder/create_embed.rs2
-rw-r--r--src/utils/builder/edit_role.rs2
-rw-r--r--src/utils/colour.rs37
4 files changed, 18 insertions, 25 deletions
diff --git a/src/model/guild.rs b/src/model/guild.rs
index a7a7edc..7b8ed60 100644
--- a/src/model/guild.rs
+++ b/src/model/guild.rs
@@ -1069,7 +1069,7 @@ impl Member {
.collect::<Vec<&Role>>();
roles.sort_by(|a, b| b.cmp(a));
- roles.iter().find(|r| r.colour.value != default.value).map(|r| r.colour)
+ roles.iter().find(|r| r.colour.0 != default.0).map(|r| r.colour)
}
/// Calculates the member's display name.
diff --git a/src/utils/builder/create_embed.rs b/src/utils/builder/create_embed.rs
index d33db8a..86d5b11 100644
--- a/src/utils/builder/create_embed.rs
+++ b/src/utils/builder/create_embed.rs
@@ -63,7 +63,7 @@ impl CreateEmbed {
/// Set the colour of the left-hand side of the embed.
pub fn colour<C: Into<Colour>>(mut self, colour: C) -> Self {
- self.0.insert("color".to_owned(), Value::U64(colour.into().value as u64));
+ self.0.insert("color".to_owned(), Value::U64(colour.into().0 as u64));
CreateEmbed(self.0)
}
diff --git a/src/utils/builder/edit_role.rs b/src/utils/builder/edit_role.rs
index b4be6d4..cea0c75 100644
--- a/src/utils/builder/edit_role.rs
+++ b/src/utils/builder/edit_role.rs
@@ -37,7 +37,7 @@ impl EditRole {
/// Creates a new builder with the values of the given [`Role`].
pub fn new(role: &Role) -> Self {
EditRole(ObjectBuilder::new()
- .insert("color", role.colour.value)
+ .insert("color", role.colour.0)
.insert("hoist", role.hoist)
.insert("managed", role.managed)
.insert("mentionable", role.mentionable)
diff --git a/src/utils/colour.rs b/src/utils/colour.rs
index acf374f..69f549d 100644
--- a/src/utils/colour.rs
+++ b/src/utils/colour.rs
@@ -65,11 +65,7 @@ macro_rules! colour {
/// [`dark_teal`]: #method.dark_teal
/// [`get_g`]: #method.get_g
#[derive(Clone, Copy, Debug, Eq, Ord, PartialEq, PartialOrd)]
-pub struct Colour {
- /// The raw inner 32-bit unsigned integer value of this Colour. This is
- /// worked with to generate values such as the red component value.
- pub value: u32,
-}
+pub struct Colour(pub u32);
impl Colour {
/// Generates a new Colour with the given integer value set.
@@ -88,10 +84,9 @@ impl Colour {
/// ```
///
/// [`get_tuple`]: #method.get_tuple
+ #[inline]
pub fn new(value: u32) -> Colour {
- Colour {
- value: value,
- }
+ Colour(value)
}
/// Generates a new Colour from an RGB value, creating an inner u32
@@ -104,8 +99,8 @@ impl Colour {
/// ```rust
/// use serenity::utils::Colour;
///
- /// assert!(Colour::from_rgb(255, 0, 0).value == 0xFF0000);
- /// assert!(Colour::from_rgb(217, 23, 211).value == 0xD917D3);
+ /// assert!(Colour::from_rgb(255, 0, 0).0 == 0xFF0000);
+ /// assert!(Colour::from_rgb(217, 23, 211).0 == 0xD917D3);
/// ```
///
/// And you can then retrieve those same RGB values via its methods:
@@ -125,14 +120,14 @@ impl Colour {
uint = (uint << 8) | (g as u32);
uint = (uint << 8) | (b as u32);
- Colour::new(uint)
+ Colour(uint)
}
#[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)),
+ Value::U64(v) => Ok(Colour(v as u32)),
+ Value::I64(v) => Ok(Colour(v as u32)),
other => Err(Error::Decode("Expected valid colour", other)),
}
}
@@ -147,7 +142,7 @@ impl Colour {
/// assert_eq!(Colour::new(6573123).get_r(), 100);
/// ```
pub fn get_r(&self) -> u8 {
- ((self.value >> 16) & 255) as u8
+ ((self.0 >> 16) & 255) as u8
}
/// Returns the green RGB component of this Colour.
@@ -160,7 +155,7 @@ impl Colour {
/// assert_eq!(Colour::new(6573123).get_g(), 76);
/// ```
pub fn get_g(&self) -> u8 {
- ((self.value >> 8) & 255) as u8
+ ((self.0 >> 8) & 255) as u8
}
/// Returns the blue RGB component of this Colour.
@@ -172,7 +167,7 @@ impl Colour {
///
/// assert_eq!(Colour::new(6573123).get_b(), 67);
pub fn get_b(&self) -> u8 {
- (self.value & 255) as u8
+ (self.0 & 255) as u8
}
/// Returns a tuple of the red, green, and blue components of this Colour.
@@ -211,7 +206,7 @@ impl From<i32> for Colour {
/// assert_eq!(Colour::from(0xDEA584).get_tuple(), (222, 165, 132));
/// ```
fn from(value: i32) -> Colour {
- Colour::new(value as u32)
+ Colour(value as u32)
}
}
@@ -228,7 +223,7 @@ impl From<u32> for Colour {
/// assert_eq!(Colour::from(6573123u32).get_r(), 100);
/// ```
fn from(value: u32) -> Colour {
- Colour::new(value)
+ Colour(value)
}
}
@@ -245,7 +240,7 @@ impl From<u64> for Colour {
/// assert_eq!(Colour::from(6573123u64).get_r(), 100);
/// ```
fn from(value: u64) -> Colour {
- Colour::new(value as u32)
+ Colour(value as u32)
}
}
@@ -309,8 +304,6 @@ colour! {
impl Default for Colour {
/// Creates a default value for a `Colour`, setting the inner value to `0`.
fn default() -> Colour {
- Colour {
- value: 0,
- }
+ Colour(0)
}
}