pub struct Color {
pub r: u8,
pub g: u8,
pub b: u8,
pub a: u8,
}Expand description
RGBA color value
Each component is stored as a u8 (0-255).
Fields§
§r: u8Red component (0-255)
g: u8Green component (0-255)
b: u8Blue component (0-255)
a: u8Alpha component (0-255, 255 = fully opaque)
Implementations§
Source§impl Color
impl Color
Sourcepub const TRANSPARENT: Color
pub const TRANSPARENT: Color
Transparent color
Sourcepub fn from_hex(hex: &str) -> Option<Color>
pub fn from_hex(hex: &str) -> Option<Color>
Create a color from a hex string (e.g., “#FF0000” or “#FF0000FF”)
Sourcepub const fn is_transparent(&self) -> bool
pub const fn is_transparent(&self) -> bool
Check if the color is fully transparent
Sourcepub fn from_name(name: &str) -> Option<Color>
pub fn from_name(name: &str) -> Option<Color>
Parse a color from a CSS/SVG color name (case-insensitive)
Supports all 140+ CSS3/SVG color keywords.
§Examples
assert_eq!(Color::from_name("red"), Some(Color::rgb(255, 0, 0)));
assert_eq!(Color::from_name("Blue"), Some(Color::rgb(0, 0, 255)));
assert_eq!(Color::from_name("LIME"), Some(Color::rgb(0, 255, 0)));
assert_eq!(Color::from_name("aliceblue"), Some(Color::rgb(240, 248, 255)));Sourcepub fn parse(input: &str) -> Option<Color>
pub fn parse(input: &str) -> Option<Color>
Parse a color from a string (hex, or CSS/SVG color name)
§Examples
assert_eq!(Color::parse("#FF0000"), Some(Color::rgb(255, 0, 0)));
assert_eq!(Color::parse("red"), Some(Color::rgb(255, 0, 0)));
assert_eq!(Color::parse("Blue"), Some(Color::rgb(0, 0, 255)));Trait Implementations§
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 UnsafeUnpin 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