Skip to content

Commit cf1c8ca

Browse files
committed
docs: Add documentation to undocumented public APIs
1 parent 5105339 commit cf1c8ca

4 files changed

Lines changed: 45 additions & 2 deletions

File tree

src/color.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,16 @@ impl Color {
4141
Self { r, g, b, a }
4242
}
4343

44+
/// Returns: `[r, g, b, a]`
45+
///
46+
/// * Red, green, blue and alpha in the range [0..1]
4447
pub fn to_array(&self) -> [f32; 4] {
4548
[self.r, self.g, self.b, self.a]
4649
}
4750

51+
/// Returns: `[r, g, b, a]`
52+
///
53+
/// * Red, green, blue and alpha in the range [0..255]
4854
pub fn to_rgba8(&self) -> [u8; 4] {
4955
[
5056
(self.r * 255.0 + 0.5) as u8,
@@ -54,6 +60,9 @@ impl Color {
5460
]
5561
}
5662

63+
/// Returns: `[r, g, b, a]`
64+
///
65+
/// * Red, green, blue and alpha in the range [0..65535]
5766
pub fn to_rgba16(&self) -> [u16; 4] {
5867
[
5968
(self.r * 65535.0 + 0.5) as u16,
@@ -63,6 +72,7 @@ impl Color {
6372
]
6473
}
6574

75+
/// Restricts R, G, B, A values to the range [0..1].
6676
pub fn clamp(&self) -> Self {
6777
Self {
6878
r: self.r.clamp(0.0, 1.0),
@@ -298,6 +308,12 @@ impl Color {
298308
Self::from_linear_rgba(r, g, b, alpha)
299309
}
300310

311+
/// Arguments:
312+
///
313+
/// * `l`: Perceived lightness
314+
/// * `c`: Chroma
315+
/// * `h`: Hue angle in radians
316+
/// * `alpha`: Alpha [0..1]
301317
pub fn from_oklcha(l: f32, c: f32, h: f32, alpha: f32) -> Self {
302318
Self::from_oklaba(l, c * h.cos(), c * h.sin(), alpha)
303319
}
@@ -316,6 +332,12 @@ impl Color {
316332

317333
#[cfg(feature = "lab")]
318334
#[deprecated = "Use [from_laba](#method.from_laba) instead."]
335+
/// Arguments:
336+
///
337+
/// * `l`: Lightness
338+
/// * `a`: Distance along the `a` axis
339+
/// * `b`: Distance along the `b` axis
340+
/// * `alpha`: Alpha [0..1]
319341
pub fn from_lab(l: f32, a: f32, b: f32, alpha: f32) -> Self {
320342
Self::from_laba(l, a, b, alpha)
321343
}
@@ -329,6 +351,7 @@ impl Color {
329351

330352
#[cfg(feature = "lab")]
331353
#[deprecated = "Use [to_laba](#method.to_laba) instead."]
354+
/// Returns: `[l, a, b, alpha]`
332355
pub fn to_lab(&self) -> [f32; 4] {
333356
self.to_laba()
334357
}
@@ -360,6 +383,12 @@ impl Color {
360383

361384
#[cfg(feature = "lab")]
362385
#[deprecated = "Use [from_lcha](#method.from_lcha) instead."]
386+
/// Arguments:
387+
///
388+
/// * `l`: Lightness
389+
/// * `c`: Chroma
390+
/// * `h`: Hue angle in radians
391+
/// * `alpha`: Alpha [0..1]
363392
pub fn from_lch(l: f32, c: f32, h: f32, alpha: f32) -> Self {
364393
Self::from_lcha(l, c, h, alpha)
365394
}
@@ -373,6 +402,7 @@ impl Color {
373402

374403
#[cfg(feature = "lab")]
375404
#[deprecated = "Use [to_lcha](#method.to_lcha) instead."]
405+
/// Returns: `[l, c, h, alpha]`
376406
pub fn to_lch(&self) -> [f32; 4] {
377407
self.to_lcha()
378408
}

src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@
9999
//! * `cint`: Enables converting [`cint`](https://crates.io/crates/cint) crate types to and from `Color`.
100100
//! * `serde`: Enables serializing (into HEX string) and deserializing (from any supported string color format) using [`serde`](https://serde.rs/) framework.
101101
102+
#![warn(missing_docs)]
103+
102104
mod color;
103105
pub use color::Color;
104106

src/named_colors.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
// https://www.w3.org/TR/css-color-4/#named-colors
2-
1+
/// Named colors defined in <https://www.w3.org/TR/css-color-4/#named-colors>.
32
pub static NAMED_COLORS: phf::Map<&'static str, [u8; 3]> = phf::phf_map! {
43
"aliceblue" => [240, 248, 255],
54
"antiquewhite" => [250, 235, 215],

src/parser.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,32 @@ use crate::Color;
66
#[cfg(feature = "named-colors")]
77
use crate::NAMED_COLORS;
88

9+
/// An error which can be returned when parsing a CSS color string.
910
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
1011
pub enum ParseColorError {
12+
/// A CSS color string was invalid hex format.
1113
InvalidHex,
14+
/// A CSS color string was invalid rgb format.
1215
InvalidRgb,
16+
/// A CSS color string was invalid hsl format.
1317
InvalidHsl,
18+
/// A CSS color string was invalid hwb format.
1419
InvalidHwb,
20+
/// A CSS color string was invalid hsv format.
1521
InvalidHsv,
22+
/// A CSS color string was invalid lab format.
1623
#[cfg(feature = "lab")]
1724
InvalidLab,
25+
/// A CSS color string was invalid lch format.
1826
#[cfg(feature = "lab")]
1927
InvalidLch,
28+
/// A CSS color string was invalid oklab format.
2029
InvalidOklab,
30+
/// A CSS color string was invalid oklch format.
2131
InvalidOklch,
32+
/// A CSS color string was invalid color function.
2233
InvalidFunction,
34+
/// A CSS color string was invalid unknown format.
2335
InvalidUnknown,
2436
}
2537

0 commit comments

Comments
 (0)