diff options
| author | Mishio595 <[email protected]> | 2018-07-24 16:33:55 -0600 |
|---|---|---|
| committer | Zeyla Hellyer <[email protected]> | 2018-08-11 17:12:05 -0700 |
| commit | 8bec4af635c3e50b111d19f6c20d56eafbb81193 (patch) | |
| tree | 183f6feab1850e95a9be528824cc62d95d6c2ccc /src/utils | |
| parent | Make default-command receive every bit of the command upon failure (diff) | |
| download | serenity-8bec4af635c3e50b111d19f6c20d56eafbb81193.tar.xz serenity-8bec4af635c3e50b111d19f6c20d56eafbb81193.zip | |
Add Colour::hex
(cherry picked from commit 6c94e05f6a8de131d0ffc913fd6ccbad602b339e)
Diffstat (limited to 'src/utils')
| -rw-r--r-- | src/utils/colour.rs | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/src/utils/colour.rs b/src/utils/colour.rs index 9e84e4e..a678a32 100644 --- a/src/utils/colour.rs +++ b/src/utils/colour.rs @@ -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 { |