pub struct Srgba {
pub r: u8,
pub g: u8,
pub b: u8,
pub a: u8,
}Expand description
A unified sRGBA color type for use across all render backends.
Srgba provides a single type that can create colors for any renderer:
SVG (CSS hex), ANSI (escape codes), EPS/PDF (0.0–1.0 arrays), image (Rgba<u8>).
§Example
use qrcode_render::colors::Srgba;
let c = Srgba::from_hex("#ff0080").unwrap();
assert_eq!(c.to_hex(), "#ff0080");
assert_eq!(c.to_css(), "rgba(255,0,128,255)");
let arr = c.to_array();
assert!((arr[0] - 1.0).abs() < 0.001);Fields§
§r: u8Red component.
g: u8Green component.
b: u8Blue component.
a: u8Alpha component (0 = transparent, 255 = opaque).
Implementations§
Source§impl Srgba
impl Srgba
Sourcepub fn from_hex(hex: &str) -> Option<Self>
pub fn from_hex(hex: &str) -> Option<Self>
Parses a hex color string (#rgb, #rgba, #rrggbb, #rrggbbaa).
Sourcepub fn to_hex(self) -> String
pub fn to_hex(self) -> String
Converts to a CSS hex string (e.g., "#ff0080" or "#ff0080c0" if alpha < 255).
Sourcepub fn to_ansi_fg(self) -> String
pub fn to_ansi_fg(self) -> String
Converts to an ANSI foreground escape sequence (\x1b[38;2;R;G;Bm).
Sourcepub fn to_ansi_bg(self) -> String
pub fn to_ansi_bg(self) -> String
Converts to an ANSI background escape sequence (\x1b[48;2;R;G;Bm).
Trait Implementations§
impl Copy for Srgba
impl Eq for Srgba
impl StructuralPartialEq for Srgba
Auto Trait Implementations§
impl Freeze for Srgba
impl RefUnwindSafe for Srgba
impl Send for Srgba
impl Sync for Srgba
impl Unpin for Srgba
impl UnsafeUnpin for Srgba
impl UnwindSafe for Srgba
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