Skip to content

Commit

Permalink
Doc improvements (#94)
Browse files Browse the repository at this point in the history
  • Loading branch information
waywardmonkeys authored Dec 15, 2024
1 parent ccac26d commit e1795f1
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
2 changes: 1 addition & 1 deletion color/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ this trait for new color spaces.
- `bytemuck`: Implement traits from `bytemuck` on [`AlphaColor`], [`ColorSpaceTag`],
[`HueDirection`], [`OpaqueColor`], [`PremulColor`], [`PremulRgba8`], and [`Rgba8`].
- `serde`: Implement `serde::Deserialize` and `serde::Serialize` on [`AlphaColor`],
[`OpaqueColor`], [`PremulColor`], [`PremulRgba8`], and [`Rgba8`].
[`DynamicColor`], [`OpaqueColor`], [`PremulColor`], [`PremulRgba8`], and [`Rgba8`].

At least one of `std` and `libm` is required; `std` overrides `libm`.

Expand Down
2 changes: 1 addition & 1 deletion color/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
//! - `bytemuck`: Implement traits from `bytemuck` on [`AlphaColor`], [`ColorSpaceTag`],
//! [`HueDirection`], [`OpaqueColor`], [`PremulColor`], [`PremulRgba8`], and [`Rgba8`].
//! - `serde`: Implement `serde::Deserialize` and `serde::Serialize` on [`AlphaColor`],
//! [`OpaqueColor`], [`PremulColor`], [`PremulRgba8`], and [`Rgba8`].
//! [`DynamicColor`], [`OpaqueColor`], [`PremulColor`], [`PremulRgba8`], and [`Rgba8`].
//!
//! At least one of `std` and `libm` is required; `std` overrides `libm`.
//!
Expand Down
19 changes: 19 additions & 0 deletions color/src/rgba8.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ use crate::{AlphaColor, PremulColor, Srgb};
/// Encoding sRGB with 8 bits per component is extremely common, as
/// it is efficient and convenient, even if limited in accuracy and
/// gamut.
///
/// This is not meant to be a general purpose color type and is
/// intended for use with [`AlphaColor::to_rgba8`] and [`OpaqueColor::to_rgba8`].
///
/// For a pre-multiplied packed representation, see [`PremulRgba8`].
///
/// [`AlphaColor::to_rgba8`]: crate::AlphaColor::to_rgba8
/// [`OpaqueColor::to_rgba8`]: crate::OpaqueColor::to_rgba8
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
#[repr(C)]
Expand All @@ -26,6 +34,8 @@ pub struct Rgba8 {

impl Rgba8 {
/// Returns the color as a `[u8; 4]`.
///
/// The color values will be in the order `[r, g, b, a]`.
#[must_use]
pub const fn to_u8_array(self) -> [u8; 4] {
[self.r, self.g, self.b, self.a]
Expand All @@ -50,6 +60,13 @@ impl From<Rgba8> for AlphaColor<Srgb> {
/// Encoding sRGB with 8 bits per component is extremely common, as
/// it is efficient and convenient, even if limited in accuracy and
/// gamut.
///
/// This is not meant to be a general purpose color type and is
/// intended for use with [`PremulColor::to_rgba8`].
///
/// For a non-pre-multiplied packed representation, see [`Rgba8`].
///
/// [`PremulColor::to_rgba8`]: crate::PremulColor::to_rgba8
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
#[repr(C)]
Expand All @@ -66,6 +83,8 @@ pub struct PremulRgba8 {

impl PremulRgba8 {
/// Returns the color as a `[u8; 4]`.
///
/// The color values will be in the order `[r, g, b, a]`.
#[must_use]
pub const fn to_u8_array(self) -> [u8; 4] {
[self.r, self.g, self.b, self.a]
Expand Down

0 comments on commit e1795f1

Please sign in to comment.