#[repr(C)]pub struct Rgba<T>where
T: ColorComponent,{
pub r: T,
pub g: T,
pub b: T,
pub a: T,
}
Expand description
RGBA Color
Fields§
§r: T
Red component
g: T
Green component
b: T
Blue component
a: T
Alpha (opacity) component
Implementations§
§impl<T> Rgba<T>where
T: ColorComponent,
impl<T> Rgba<T>where
T: ColorComponent,
pub const TRANSPARENT_WHITE: Rgba<T> = _
pub const TRANSPARENT_WHITE: Rgba<T> = _
rgba(255, 255, 255, 0)
pub const TRANSPARENT_BLACK: Rgba<T> = _
pub const TRANSPARENT_BLACK: Rgba<T> = _
rgba(0, 0, 0, 0)
§impl<T> Rgba<T>where
T: ColorComponent,
impl<T> Rgba<T>where
T: ColorComponent,
pub fn opaque(r: T, g: T, b: T) -> Rgba<T>
pub fn opaque(r: T, g: T, b: T) -> Rgba<T>
Construct Rgba
from red, green, and blue components, fully opaque (max alpha).
pub fn new(r: T, g: T, b: T, a: T) -> Rgba<T>
pub fn new(r: T, g: T, b: T, a: T) -> Rgba<T>
Construct Rgba
from red, green, blue, and alpha components.
pub fn map_rgb<F, U>(self, f: F) -> Rgba<U>where
F: Fn(T) -> U,
U: ColorComponent,
pub fn map_rgb<F, U>(self, f: F) -> Rgba<U>where
F: Fn(T) -> U,
U: ColorComponent,
Convert Rgba<T>
to Rgba<U>
by applying a function to every color component excluding alpha.
The resulting alpha is calculated by applying ColorComponent::convert() method.
§Examples
let initial = Rgba::new(0.7, 0.4, 1.0, 1.0);
let f = |component: f32| component / 2.0;
assert_eq!(initial.map_rgb(f), Rgba::new(0.35, 0.2, 0.5, 1.0));
pub fn map<F, U>(self, f: F) -> Rgba<U>where
F: Fn(T) -> U,
U: ColorComponent,
pub fn map<F, U>(self, f: F) -> Rgba<U>where
F: Fn(T) -> U,
U: ColorComponent,
Convert Rgba<T>
to Rgba<U>
by applying a function to every color component.
§Examples
let initial = Rgba::new(0.7, 0.4, 1.0, 1.0);
let f = |component: f32| component / 2.0;
assert_eq!(initial.map(f), Rgba::new(0.35, 0.2, 0.5, 0.5));
pub fn zip_map<F, U, V>(self, other: Rgba<U>, f: F) -> Rgba<V>
pub fn zip_map<F, U, V>(self, other: Rgba<U>, f: F) -> Rgba<V>
Applies a function to every component of two colors and produces a new color.
§Examples
let a = Rgba::new(0.2, 0.1, 0.3, 0.6);
let b = Rgba::new(0.5, 0.3, 0.2, 0.2);
let f = |a: f32, b: f32| a + b;
assert_eq!(a.zip_map(b, f), Rgba::new(0.7, 0.4, 0.5, 0.8));
pub fn convert<U>(self) -> Rgba<U>where
U: ColorComponent,
pub fn convert<U>(self) -> Rgba<U>where
U: ColorComponent,
Convert Rgba<T>
to Rgba<U>
by applying ColorComponent::convert()
method.
§Examples
assert_eq!(Rgba::opaque(0, 255, 0).convert(), Rgba::opaque(0.0, 1.0, 0.0));
pub fn lerp(start: Rgba<T>, end: Rgba<T>, t: f32) -> Rgba<T>
pub fn lerp(start: Rgba<T>, end: Rgba<T>, t: f32) -> Rgba<T>
Linearly interpolate between start
and end
values.
§Examples
let start = Rgba::opaque(0.0, 0.0, 0.0);
let end = Rgba::opaque(1.0, 1.0, 1.0);
let interpolated = Rgba::lerp(start, end, 0.3);
assert!(interpolated.r - 0.3 < 1e-5);
assert!(interpolated.g - 0.3 < 1e-5);
assert!(interpolated.b - 0.3 < 1e-5);
assert_eq!(interpolated.a, 1.0);
Methods from Deref<Target = [T; 4]>§
1.57.0 · sourcepub fn as_slice(&self) -> &[T]
pub fn as_slice(&self) -> &[T]
Returns a slice containing the entire array. Equivalent to &s[..]
.
1.57.0 · sourcepub fn as_mut_slice(&mut self) -> &mut [T]
pub fn as_mut_slice(&mut self) -> &mut [T]
Returns a mutable slice containing the entire array. Equivalent to
&mut s[..]
.
sourcepub fn each_ref(&self) -> [&T; N]
🔬This is a nightly-only experimental API. (array_methods
)
pub fn each_ref(&self) -> [&T; N]
array_methods
)Borrows each element and returns an array of references with the same
size as self
.
§Example
#![feature(array_methods)]
let floats = [3.1, 2.7, -1.0];
let float_refs: [&f64; 3] = floats.each_ref();
assert_eq!(float_refs, [&3.1, &2.7, &-1.0]);
This method is particularly useful if combined with other methods, like
map
. This way, you can avoid moving the original
array if its elements are not Copy
.
#![feature(array_methods)]
let strings = ["Ferris".to_string(), "♥".to_string(), "Rust".to_string()];
let is_ascii = strings.each_ref().map(|s| s.is_ascii());
assert_eq!(is_ascii, [true, false, true]);
// We can still access the original array: it has not been moved.
assert_eq!(strings.len(), 3);
sourcepub fn each_mut(&mut self) -> [&mut T; N]
🔬This is a nightly-only experimental API. (array_methods
)
pub fn each_mut(&mut self) -> [&mut T; N]
array_methods
)Borrows each element mutably and returns an array of mutable references
with the same size as self
.
§Example
#![feature(array_methods)]
let mut floats = [3.1, 2.7, -1.0];
let float_refs: [&mut f64; 3] = floats.each_mut();
*float_refs[0] = 0.0;
assert_eq!(float_refs, [&mut 0.0, &mut 2.7, &mut -1.0]);
assert_eq!(floats, [0.0, 2.7, -1.0]);
sourcepub fn split_array_ref<const M: usize>(&self) -> (&[T; M], &[T])
🔬This is a nightly-only experimental API. (split_array
)
pub fn split_array_ref<const M: usize>(&self) -> (&[T; M], &[T])
split_array
)Divides one array reference into two at an index.
The first will contain all indices from [0, M)
(excluding
the index M
itself) and the second will contain all
indices from [M, N)
(excluding the index N
itself).
§Panics
Panics if M > N
.
§Examples
#![feature(split_array)]
let v = [1, 2, 3, 4, 5, 6];
{
let (left, right) = v.split_array_ref::<0>();
assert_eq!(left, &[]);
assert_eq!(right, &[1, 2, 3, 4, 5, 6]);
}
{
let (left, right) = v.split_array_ref::<2>();
assert_eq!(left, &[1, 2]);
assert_eq!(right, &[3, 4, 5, 6]);
}
{
let (left, right) = v.split_array_ref::<6>();
assert_eq!(left, &[1, 2, 3, 4, 5, 6]);
assert_eq!(right, &[]);
}
sourcepub fn split_array_mut<const M: usize>(&mut self) -> (&mut [T; M], &mut [T])
🔬This is a nightly-only experimental API. (split_array
)
pub fn split_array_mut<const M: usize>(&mut self) -> (&mut [T; M], &mut [T])
split_array
)Divides one mutable array reference into two at an index.
The first will contain all indices from [0, M)
(excluding
the index M
itself) and the second will contain all
indices from [M, N)
(excluding the index N
itself).
§Panics
Panics if M > N
.
§Examples
#![feature(split_array)]
let mut v = [1, 0, 3, 0, 5, 6];
let (left, right) = v.split_array_mut::<2>();
assert_eq!(left, &mut [1, 0][..]);
assert_eq!(right, &mut [3, 0, 5, 6]);
left[1] = 2;
right[1] = 4;
assert_eq!(v, [1, 2, 3, 4, 5, 6]);
sourcepub fn rsplit_array_ref<const M: usize>(&self) -> (&[T], &[T; M])
🔬This is a nightly-only experimental API. (split_array
)
pub fn rsplit_array_ref<const M: usize>(&self) -> (&[T], &[T; M])
split_array
)Divides one array reference into two at an index from the end.
The first will contain all indices from [0, N - M)
(excluding
the index N - M
itself) and the second will contain all
indices from [N - M, N)
(excluding the index N
itself).
§Panics
Panics if M > N
.
§Examples
#![feature(split_array)]
let v = [1, 2, 3, 4, 5, 6];
{
let (left, right) = v.rsplit_array_ref::<0>();
assert_eq!(left, &[1, 2, 3, 4, 5, 6]);
assert_eq!(right, &[]);
}
{
let (left, right) = v.rsplit_array_ref::<2>();
assert_eq!(left, &[1, 2, 3, 4]);
assert_eq!(right, &[5, 6]);
}
{
let (left, right) = v.rsplit_array_ref::<6>();
assert_eq!(left, &[]);
assert_eq!(right, &[1, 2, 3, 4, 5, 6]);
}
sourcepub fn rsplit_array_mut<const M: usize>(&mut self) -> (&mut [T], &mut [T; M])
🔬This is a nightly-only experimental API. (split_array
)
pub fn rsplit_array_mut<const M: usize>(&mut self) -> (&mut [T], &mut [T; M])
split_array
)Divides one mutable array reference into two at an index from the end.
The first will contain all indices from [0, N - M)
(excluding
the index N - M
itself) and the second will contain all
indices from [N - M, N)
(excluding the index N
itself).
§Panics
Panics if M > N
.
§Examples
#![feature(split_array)]
let mut v = [1, 0, 3, 0, 5, 6];
let (left, right) = v.rsplit_array_mut::<4>();
assert_eq!(left, &mut [1, 0]);
assert_eq!(right, &mut [3, 0, 5, 6][..]);
left[1] = 2;
right[1] = 4;
assert_eq!(v, [1, 2, 3, 4, 5, 6]);
sourcepub fn as_ascii(&self) -> Option<&[AsciiChar; N]>
🔬This is a nightly-only experimental API. (ascii_char
)
pub fn as_ascii(&self) -> Option<&[AsciiChar; N]>
ascii_char
)Converts this array of bytes into a array of ASCII characters,
or returns None
if any of the characters is non-ASCII.
§Examples
#![feature(ascii_char)]
#![feature(const_option)]
const HEX_DIGITS: [std::ascii::Char; 16] =
*b"0123456789abcdef".as_ascii().unwrap();
assert_eq!(HEX_DIGITS[1].as_str(), "1");
assert_eq!(HEX_DIGITS[10].as_str(), "a");
sourcepub unsafe fn as_ascii_unchecked(&self) -> &[AsciiChar; N]
🔬This is a nightly-only experimental API. (ascii_char
)
pub unsafe fn as_ascii_unchecked(&self) -> &[AsciiChar; N]
ascii_char
)Converts this array of bytes into a array of ASCII characters, without checking whether they’re valid.
§Safety
Every byte in the array must be in 0..=127
, or else this is UB.
Trait Implementations§
§impl<T> Approx for Rgba<T>where
T: ColorComponent + Approx,
impl<T> Approx for Rgba<T>where
T: ColorComponent + Approx,
§fn approx_distance_to(&self, other: &Rgba<T>) -> f32
fn approx_distance_to(&self, other: &Rgba<T>) -> f32
§fn approx_eq(&self, other: &Self) -> bool
fn approx_eq(&self, other: &Self) -> bool
§fn approx_eq_eps(&self, other: &Self, eps: f32) -> bool
fn approx_eq_eps(&self, other: &Self, eps: f32) -> bool
§impl<T> Clone for Rgba<T>where
T: Clone + ColorComponent,
impl<T> Clone for Rgba<T>where
T: Clone + ColorComponent,
§impl<T> Debug for Rgba<T>where
T: Debug + ColorComponent,
impl<T> Debug for Rgba<T>where
T: Debug + ColorComponent,
§impl<T> Deref for Rgba<T>where
T: ColorComponent,
impl<T> Deref for Rgba<T>where
T: ColorComponent,
§impl<T> DerefMut for Rgba<T>where
T: ColorComponent,
impl<T> DerefMut for Rgba<T>where
T: ColorComponent,
§impl<'de, T> Deserialize<'de> for Rgba<T>where
T: ColorComponent + Deserialize<'de>,
impl<'de, T> Deserialize<'de> for Rgba<T>where
T: ColorComponent + Deserialize<'de>,
§fn deserialize<__D>(
__deserializer: __D
) -> Result<Rgba<T>, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D
) -> Result<Rgba<T>, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
§impl<T> Display for Rgba<T>where
T: ColorComponent,
impl<T> Display for Rgba<T>where
T: ColorComponent,
§impl<C1, C2> From<Hsla<C1>> for Rgba<C2>where
C1: ColorComponent,
C2: ColorComponent,
impl<C1, C2> From<Hsla<C1>> for Rgba<C2>where
C1: ColorComponent,
C2: ColorComponent,
§impl<C1, C2> From<Hsva<C1>> for Rgba<C2>where
C1: ColorComponent,
C2: ColorComponent,
impl<C1, C2> From<Hsva<C1>> for Rgba<C2>where
C1: ColorComponent,
C2: ColorComponent,
§impl<C1, C2> From<Rgba<C1>> for Hsla<C2>where
C1: ColorComponent,
C2: ColorComponent,
impl<C1, C2> From<Rgba<C1>> for Hsla<C2>where
C1: ColorComponent,
C2: ColorComponent,
§impl<C1, C2> From<Rgba<C1>> for Hsva<C2>where
C1: ColorComponent,
C2: ColorComponent,
impl<C1, C2> From<Rgba<C1>> for Hsva<C2>where
C1: ColorComponent,
C2: ColorComponent,
§impl<T> From<Rgba<T>> for Stringwhere
T: ColorComponent,
impl<T> From<Rgba<T>> for Stringwhere
T: ColorComponent,
§impl<T> Hash for Rgba<T>where
T: Hash + ColorComponent,
impl<T> Hash for Rgba<T>where
T: Hash + ColorComponent,
§impl<T> Mul for Rgba<T>where
T: ColorComponent,
impl<T> Mul for Rgba<T>where
T: ColorComponent,
§impl<T> PartialEq for Rgba<T>where
T: PartialEq + ColorComponent,
impl<T> PartialEq for Rgba<T>where
T: PartialEq + ColorComponent,
§impl<T> Serialize for Rgba<T>where
T: ColorComponent + Serialize,
impl<T> Serialize for Rgba<T>where
T: ColorComponent + Serialize,
§fn serialize<__S>(
&self,
__serializer: __S
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
source§impl TexturePixel for Rgba<f32>
impl TexturePixel for Rgba<f32>
§impl<T> TryFrom<&str> for Rgba<T>where
T: ColorComponent,
impl<T> TryFrom<&str> for Rgba<T>where
T: ColorComponent,
§impl<T> TryFrom<String> for Rgba<T>where
T: ColorComponent,
impl<T> TryFrom<String> for Rgba<T>where
T: ColorComponent,
source§impl VertexAttribute for Rgba<f32>
impl VertexAttribute for Rgba<f32>
impl<T> Copy for Rgba<T>where
T: Copy + ColorComponent,
impl<T> Eq for Rgba<T>where
T: Eq + ColorComponent,
impl<T> StructuralEq for Rgba<T>where
T: ColorComponent,
impl<T> StructuralPartialEq for Rgba<T>where
T: ColorComponent,
Auto Trait Implementations§
impl<T> RefUnwindSafe for Rgba<T>where
T: RefUnwindSafe,
impl<T> Send for Rgba<T>where
T: Send,
impl<T> Sync for Rgba<T>where
T: Sync,
impl<T> Unpin for Rgba<T>where
T: Unpin,
impl<T> UnwindSafe for Rgba<T>where
T: UnwindSafe,
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
§impl<T> CompatExt for T
impl<T> CompatExt for T
source§impl<T> Configurable for T
impl<T> Configurable for T
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.§impl<T> DowncastSync for T
impl<T> DowncastSync for T
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.