INNER CODE UNIT · Rust
to_rgba
sharkdp/pastel · src/lib.rs:242
pub fn to_rgba(&self) -> RGBA<u8> {
RGBA::<u8>::from(self)
}
/// Format the color as a RGB-representation string (`rgba(255, 127, 0, 0.5)`). If the alpha channel
/// is `1.0`, the simplified `rgb()` format will be used instead.
pub fn to_rgb_string(&self, format: Format) -> String {
let rgba = RGBA::<u8>::from(self);
let space = if format == Format::Spaces { " " } else { "" };
let (a_prefix, a) = if self.alpha == 1.0 {
("", "".to_string())
} else {
(
"a",
format!(
",{space}{alpha}",
alpha = MaxPrecision::wrap(3, rgba.alpha),
space = space