named_colour/lib.rs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
#![cfg_attr(docsrs, feature(doc_cfg))]
#![warn(missing_docs)]
// #![cfg_attr(docsrs, warn(rustdoc::missing_doc_code_examples))]
#![cfg_attr(docsrs, warn(rustdoc::invalid_codeblock_attributes))]
#![allow(dead_code)]
//! Provides Hex Codes for colours:
//! - enums that return a hex code string for named colours
//! - rgb colour struct to configure a colour an rgb colour and display as decimal or hex
//!
//! ## Examples
//!
//! ### Use Basic colour
//!
//!```toml
//! [dependencies]
//! named-colour = "0.3.5"
//!
//!```
//!
#[cfg_attr(
not(feature = "extended"),
doc = r##"
```
use named_colour::Basic;
println!("The colour Hex Code is: {} for the RGB colour Aqua: {}",
Basic::Aqua,
Basic::Aqua.to_rgb()
);
assert_eq!("rgb(0,255,255)", Basic::Aqua.to_rgb().to_string());
```
"##
)]
#[cfg_attr(
feature = "extended",
doc = r##"
### Use Extended colour
Enable the feature in the toml file:
```toml
[dependencies]
named-colour = { version = "0.3.5", features = ["extended"]}
```
```
use named_colour::ext::Purple;
println!("The colour Hex Code is: {} for the RGB colour Dark Orchid: {}",
Purple::DarkOrchid,
Purple::DarkOrchid.to_rgb()
);
```
"##
)]
///
/// ### Create a custom colour
///
///```
/// use named_colour::ToHex;
/// use rgb::Rgb;
/// fn main() {
/// assert_eq!("#CCCCCC", &Rgb::new(204, 204, 204).as_hex());
/// let colour = Rgb::new(12, 24, 48);
/// assert_eq!("#0C1830", colour.as_hex());
/// let colour = Rgb::new(12, 4, 8);
/// assert_eq!("#0C0408", colour.as_hex());
/// }
///```
///
/// ## Features
/// - Basic contains just 16 colours with 18 names (default)
/// - Extended contains a fuller set of colours divided in 11 collections
///
/// To use the extended colour set only configure toml with no-default features
///
///```toml
///[dependencies]
///named-colour = { version = "0.3.5", default_features = false, features = ["extended"]}
///```
///
///
///
mod to_hex;
#[cfg(not(feature = "extended"))]
mod basic;
#[cfg(feature = "extended")]
pub mod ext;
pub use crate::to_hex::ToHex;
pub use rgb::RGB8;
#[cfg(not(feature = "extended"))]
pub use basic::Basic;
#[cfg(feature = "extended")]
pub use ext::name_colour;
#[cfg(feature = "extended")]
pub use ext::random_named_colour;
#[cfg(feature = "extended")]
pub use ext::Black;
#[cfg(feature = "extended")]
pub use ext::Blue;
#[cfg(feature = "extended")]
pub use ext::Brown;
#[cfg(feature = "extended")]
pub use ext::Cyan;
#[cfg(feature = "extended")]
pub use ext::ExtendedColour;
#[cfg(feature = "extended")]
pub use ext::Green;
#[cfg(feature = "extended")]
pub use ext::Purple;
#[cfg(feature = "extended")]
pub use ext::Red;
#[cfg(feature = "extended")]
pub use ext::White;
#[cfg(feature = "extended")]
pub use ext::Yellow;
/// Prefixes
///
/// Prefixes allowed to 6 character hex code to specify colour
pub enum Prefix {
/// No prefix yields 6 character string
None,
/// Prefix # yields 7 character string
Hash,
}