pub struct Color {
pub r: u8,
pub g: u8,
pub b: u8,
pub a: u8,
}Expand description
RGBA color representation with 8-bit components
Fields§
§r: u8Red component
g: u8Green component
b: u8Blue component
a: u8Alpha component
Implementations§
Source§impl Color
impl Color
Sourcepub const fn gray(shade: u8) -> Self
pub const fn gray(shade: u8) -> Self
Create a grayscale color from a single intensity value
§Arguments
shade- Gray intensity
§Example
use simple_color::Color;
let gray = Color::gray(0x80);
let dark_gray = Color::gray(0x40);
let light_gray = Color::gray(0xC0);
let black = Color::gray(0);
let white = Color::gray(0xFF);
assert_eq!(gray, Color::rgb(0x80, 0x80, 0x80));
assert_eq!(black, Color::BLACK);
assert_eq!(white, Color::WHITE);Trait Implementations§
Source§impl FromStr for Color
impl FromStr for Color
Source§fn from_str(name: &str) -> Result<Self, Self::Err>
fn from_str(name: &str) -> Result<Self, Self::Err>
Parse color from hexadecimal string.
Supported formats:
- Grayscale - 1 or 2 characters representing brightness
RGB- “RGB” or “RRGGBB”RGBA- “RGBA” or “RRGGBBAA”
§Example
use simple_color::{Color, ColorParsingError};
let red: Color = "FF0000".parse().unwrap();
assert_eq!(red, Color::RED);
let semi_transparent_orange: Color = "ff800080".parse().unwrap();
assert_eq!(semi_transparent_orange, Color::rgba(0xFF, 0x80, 0, 0x80));
let gray: Color = "80".parse().unwrap();
assert_eq!(gray, Color::gray(0x80));
let invalid_char: Result<Color, _> = "80FG00".parse();
assert_eq!(invalid_char, Err(ColorParsingError::InvalidChar('G')));
let invalid_length: Result<Color, _> = "FF80000".parse();
assert_eq!(invalid_length, Err(ColorParsingError::InvalidLength(7)));Source§type Err = ColorParsingError
type Err = ColorParsingError
The associated error which can be returned from parsing.
impl Copy for Color
impl Eq for Color
impl StructuralPartialEq for Color
Auto Trait Implementations§
impl Freeze for Color
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