Debian Codegraph @

src/named.rs

raw symbols SCIP
1 //! A collection of named color constants. Can be toggled with the `"named"` and
2 //! `"named_from_str"` Cargo features.
3 //!
4 //! They are taken from the [SVG keyword
5 //! colors](https://www.w3.org/TR/SVG11/types.html#ColorKeywords) (same as in
6 //! CSS3) and they can be used as if they were pixel values:
7 //!
8 //! ```
9 //! use palette::Srgb;
10 //! use palette::named;
11 //!
12 //! //From constant
13 //! let from_const = Srgb::<f32>::from_format(named::OLIVE).into_linear();
14 #![cfg_attr(feature = "named_from_str", doc = "")]
15 #![cfg_attr(feature = "named_from_str", doc = "//From name string")]
16 #![cfg_attr(feature = "named_from_str", doc = "let olive = named::from_str(\"olive\").expect(\"unknown color\");")]
17 #![cfg_attr(feature = "named_from_str", doc = "let from_str = Srgb::<f32>::from_format(olive).into_linear();")]
18 #![cfg_attr(feature = "named_from_str", doc = "")]
19 #![cfg_attr(feature = "named_from_str", doc = "assert_eq!(from_const, from_str);")]
20 //! ```
21
22 include!(concat!(env!("OUT_DIR"), "/named.rs"));
23
24 /// Get a SVG/CSS3 color by name. Can be toggled with the `"named_from_str"`
25 /// Cargo feature.
26 ///
27 /// The names are the same as the constants, but lower case.
28 #[cfg(feature = "named_from_str")]
29 pub fn from_str(name: &str) -> Option<crate::Srgb<u8>> {
30 COLORS.get(name).cloned()
31 }