Skip to content

Commit

Permalink
Add Colour::hex
Browse files Browse the repository at this point in the history
(cherry picked from commit 6c94e05)
  • Loading branch information
Mishio595 authored and Zeyla Hellyer committed Aug 12, 2018
1 parent 46b4194 commit 8bec4af
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/utils/colour.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,22 @@ impl Colour {
/// [`g`]: #method.g
/// [`b`]: #method.b
pub fn tuple(&self) -> (u8, u8, u8) { (self.r(), self.g(), self.b()) }

/// Returns a hexadecimal string of this Colour.
///
/// This is equivalent to passing the integer value through
/// `std::fmt::UpperHex` with 0 padding and 6 width
///
/// # Examples
///
/// ```rust
/// use serenity::utils::Colour;
///
/// assert_eq!(Colour::new(6573123).hex(), "644C43");
/// ```
pub fn hex(&self) -> String {
format!("{:06X}", self.0)
}
}

impl From<i32> for Colour {
Expand Down

0 comments on commit 8bec4af

Please sign in to comment.