pub struct Color {
pub r: u8,
pub g: u8,
pub b: u8,
pub a: u8,
}
Expand description
A Color with red, green, blue, and alpha components, with each component stored as a u8
.
Colors can be deserialized from strings consisting of either
one of the predefined names: white
, black
, red
, green
,
blue
, cyan
, yellow
, or magenta
.
Or, the #
character followed by a hex color code. The hex code can either
be 8, 6, 4 or 3 digits long.
- 8 digits - each set of 2 digits specifies one color component - red, green, blue, then alpha
- 6 digits - each set of 2 digits specifies one color component - red, green, and blue. Alpha is assumed to be the maximum value of FF.
- 4 digits - each single digit specifies one color component - red, green, blue, then alpha, with half precision.
- 3 digits - each single digit specifies one color component - red, green, then blue. Alpha ia assumed to be the maximum value of F.
For the 4 and 3 digit variants - each component has one of 16 possible values. The value is multiplied by 17 to determine the
corresponding full precision value. For example,
0
maps to00
,F
maps toFF
, and8
maps to88
.
Fields§
§r: u8
The red component
g: u8
The green component
b: u8
The blue component
a: u8
The alpha or transparency component
Implementations§
Trait Implementations§
source§impl<'de> Deserialize<'de> for Color
impl<'de> Deserialize<'de> for Color
source§fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Color, D::Error>
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Color, D::Error>
Deserialize this value from the given Serde deserializer. Read more
source§impl PartialEq<Color> for Color
impl PartialEq<Color> for Color
impl Copy for Color
impl Eq for Color
impl StructuralEq for Color
impl StructuralPartialEq for Color
Auto Trait Implementations§
impl RefUnwindSafe for Color
impl Send for Color
impl Sync for Color
impl Unpin for Color
impl UnwindSafe for Color
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
source§impl<T> Content for Twhere
T: Copy,
impl<T> Content for Twhere T: Copy,
source§unsafe fn read<F, E>(size: usize, f: F) -> Result<T, E>where
F: FnOnce(&mut T) -> Result<(), E>,
unsafe fn read<F, E>(size: usize, f: F) -> Result<T, E>where F: FnOnce(&mut T) -> Result<(), E>,
Prepares an output buffer, then turns this buffer into an
Owned
.
User-provided closure F
must only write to and not read from &mut Self
.source§fn get_elements_size() -> usize
fn get_elements_size() -> usize
Returns the size of each element.
source§fn to_void_ptr(&self) -> *const ()
fn to_void_ptr(&self) -> *const ()
Produces a pointer to the data.
source§fn ref_from_ptr<'a>(ptr: *mut (), size: usize) -> Option<*mut T>
fn ref_from_ptr<'a>(ptr: *mut (), size: usize) -> Option<*mut T>
Builds a pointer to this type from a raw pointer.
source§fn is_size_suitable(size: usize) -> bool
fn is_size_suitable(size: usize) -> bool
Returns true if the size is suitable to store a type like this.
source§impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Qwhere Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,
source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key
and return true
if they are equal.