Skip to main content

RGBA

Struct RGBA 

Source
pub struct RGBA {
    pub red: u8,
    pub green: u8,
    pub blue: u8,
    pub alpha: u8,
}
Expand description

A color with red, green, blue, and alpha components, in a byte each.

Fields§

§red: u8

The red component.

§green: u8

The green component.

§blue: u8

The blue component.

§alpha: u8

The alpha component.

Implementations§

Source§

impl RGBA

Source

pub fn from_floats(red: f32, green: f32, blue: f32, alpha: f32) -> Self

Constructs a new RGBA value from float components. It expects the red, green, blue and alpha channels in that order, and all values will be clamped to the 0.0 … 1.0 range.

Source

pub fn transparent() -> Self

Returns a transparent color.

Source

pub fn new(red: u8, green: u8, blue: u8, alpha: f32) -> Self

Same thing, but with u8 values instead of floats in the 0 to 1 range.

Examples found in repository?
examples/custom_at_rule.rs (line 271)
267  fn visit_token(&mut self, token: &mut TokenOrValue<'i>) -> Result<(), Self::Error> {
268    match token {
269      TokenOrValue::Function(f) if f.name == "theme" => match f.arguments.0.first() {
270        Some(TokenOrValue::Token(Token::String(s))) => match s.as_ref() {
271          "blue-500" => *token = TokenOrValue::Color(CssColor::RGBA(RGBA::new(0, 0, 255, 1.0))),
272          "red-500" => *token = TokenOrValue::Color(CssColor::RGBA(RGBA::new(255, 0, 0, 1.0))),
273          _ => {}
274        },
275        _ => {}
276      },
277      _ => {}
278    }
279
280    token.visit_children(self)
281  }
Source

pub fn red_f32(&self) -> f32

Returns the red channel in a floating point number form, from 0 to 1.

Source

pub fn green_f32(&self) -> f32

Returns the green channel in a floating point number form, from 0 to 1.

Source

pub fn blue_f32(&self) -> f32

Returns the blue channel in a floating point number form, from 0 to 1.

Source

pub fn alpha_f32(&self) -> f32

Returns the alpha channel in a floating point number form, from 0 to 1.

Trait Implementations§

Source§

impl Clone for RGBA

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for RGBA

Source§

impl Debug for RGBA

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl From<&RGBA> for RGB

Source§

fn from(rgb: &RGBA) -> Self

Converts to this type from the input type.
Source§

impl From<A98> for RGBA

Source§

fn from(t: A98) -> RGBA

Converts to this type from the input type.
Source§

impl From<FloatColor> for RGBA

Source§

fn from(color: FloatColor) -> RGBA

Converts to this type from the input type.
Source§

impl From<HSL> for RGBA

Source§

fn from(t: HSL) -> RGBA

Converts to this type from the input type.
Source§

impl From<HWB> for RGBA

Source§

fn from(t: HWB) -> RGBA

Converts to this type from the input type.
Source§

impl From<LAB> for RGBA

Source§

fn from(t: LAB) -> RGBA

Converts to this type from the input type.
Source§

impl From<LABColor> for RGBA

Source§

fn from(color: LABColor) -> RGBA

Converts to this type from the input type.
Source§

impl From<LCH> for RGBA

Source§

fn from(t: LCH) -> RGBA

Converts to this type from the input type.
Source§

impl From<OKLAB> for RGBA

Source§

fn from(t: OKLAB) -> RGBA

Converts to this type from the input type.
Source§

impl From<OKLCH> for RGBA

Source§

fn from(t: OKLCH) -> RGBA

Converts to this type from the input type.
Source§

impl From<P3> for RGBA

Source§

fn from(t: P3) -> RGBA

Converts to this type from the input type.
Source§

impl From<PredefinedColor> for RGBA

Source§

fn from(color: PredefinedColor) -> RGBA

Converts to this type from the input type.
Source§

impl From<ProPhoto> for RGBA

Source§

fn from(t: ProPhoto) -> RGBA

Converts to this type from the input type.
Source§

impl From<RGB> for RGBA

Source§

fn from(rgb: RGB) -> Self

Converts to this type from the input type.
Source§

impl From<RGBA> for SRGB

Source§

fn from(rgb: RGBA) -> SRGB

Converts to this type from the input type.
Source§

impl From<RGBA> for RGB

Source§

fn from(rgb: RGBA) -> Self

Converts to this type from the input type.
Source§

impl From<RGBA> for LAB

Source§

fn from(t: RGBA) -> LAB

Converts to this type from the input type.
Source§

impl From<RGBA> for LCH

Source§

fn from(t: RGBA) -> LCH

Converts to this type from the input type.
Source§

impl From<RGBA> for OKLAB

Source§

fn from(t: RGBA) -> OKLAB

Converts to this type from the input type.
Source§

impl From<RGBA> for OKLCH

Source§

fn from(t: RGBA) -> OKLCH

Converts to this type from the input type.
Source§

impl From<RGBA> for P3

Source§

fn from(t: RGBA) -> P3

Converts to this type from the input type.
Source§

impl From<RGBA> for SRGBLinear

Source§

fn from(t: RGBA) -> SRGBLinear

Converts to this type from the input type.
Source§

impl From<RGBA> for A98

Source§

fn from(t: RGBA) -> A98

Converts to this type from the input type.
Source§

impl From<RGBA> for ProPhoto

Source§

fn from(t: RGBA) -> ProPhoto

Converts to this type from the input type.
Source§

impl From<RGBA> for XYZd50

Source§

fn from(t: RGBA) -> XYZd50

Converts to this type from the input type.
Source§

impl From<RGBA> for XYZd65

Source§

fn from(t: RGBA) -> XYZd65

Converts to this type from the input type.
Source§

impl From<RGBA> for Rec2020

Source§

fn from(t: RGBA) -> Rec2020

Converts to this type from the input type.
Source§

impl From<RGBA> for HSL

Source§

fn from(t: RGBA) -> HSL

Converts to this type from the input type.
Source§

impl From<RGBA> for HWB

Source§

fn from(t: RGBA) -> HWB

Converts to this type from the input type.
Source§

impl From<RGBA> for CssColor

Source§

fn from(color: RGBA) -> CssColor

Converts to this type from the input type.
Source§

impl From<Rec2020> for RGBA

Source§

fn from(t: Rec2020) -> RGBA

Converts to this type from the input type.
Source§

impl From<SRGB> for RGBA

Source§

fn from(rgb: SRGB) -> RGBA

Converts to this type from the input type.
Source§

impl From<SRGBLinear> for RGBA

Source§

fn from(t: SRGBLinear) -> RGBA

Converts to this type from the input type.
Source§

impl From<XYZd50> for RGBA

Source§

fn from(t: XYZd50) -> RGBA

Converts to this type from the input type.
Source§

impl From<XYZd65> for RGBA

Source§

fn from(t: XYZd65) -> RGBA

Converts to this type from the input type.
Source§

impl PartialEq for RGBA

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for RGBA

Source§

impl TryFrom<&CssColor> for RGBA

Source§

type Error = ()

The type returned in the event of a conversion error.
Source§

fn try_from(color: &CssColor) -> Result<RGBA, ()>

Performs the conversion.
Source§

impl TryFrom<CssColor> for RGBA

Source§

type Error = ()

The type returned in the event of a conversion error.
Source§

fn try_from(color: CssColor) -> Result<RGBA, ()>

Performs the conversion.
Source§

impl<'i, V: ?Sized + Visitor<'i, T>, T: Visit<'i, T, V>> Visit<'i, T, V> for RGBA

Available on crate feature visitor only.
Source§

const CHILD_TYPES: VisitTypes

The types of values contained within this value and its children. This is used to skip branches that don’t have any values requested by the Visitor.
Source§

fn visit_children(&mut self, _: &mut V) -> Result<(), V::Error>

Visit the children of this value.
Source§

fn visit(&mut self, visitor: &mut V) -> Result<(), V::Error>

Visits the value by calling an appropriate method on the Visitor. If no corresponding visitor method exists, then the children are visited.

Auto Trait Implementations§

§

impl Freeze for RGBA

§

impl RefUnwindSafe for RGBA

§

impl Send for RGBA

§

impl Sync for RGBA

§

impl Unpin for RGBA

§

impl UnsafeUnpin for RGBA

§

impl UnwindSafe for RGBA

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> ArchivePointee for T

Source§

type ArchivedMetadata = ()

The archived version of the pointer metadata for this type.
Source§

fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata

Converts some archived metadata to the pointer metadata for itself.
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> LayoutRaw for T

Source§

fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>

Returns the layout of the type.
Source§

impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
where T: SharedNiching<N1, N2>, N1: Niching<T>, N2: Niching<T>,

Source§

unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool

Returns whether the given value has been niched. Read more
Source§

fn resolve_niched(out: Place<NichedOption<T, N1>>)

Writes data to out indicating that a T is niched.
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Pointee for T

Source§

type Metadata = ()

The metadata type for pointers and references to this type.
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.