| 1 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/::Filerust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/File#; |
| 2 | |
| 3 | pub fn buildrust-analyzer cargo palette 0.7.6 named/build().() { |
| 4 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/::Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#; |
| 5 | |
| 6 | let out_dir = ::stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::envrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/::varrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/var().("OUT_DIR").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 7 | let dest_path = Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]new().(&out_dir).joinrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]join().("named.rs"); |
| 8 | let mut writer = Filerust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/File#::createrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[File]create().(dest_path).expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("couldn't create named.rs"); |
| 9 | build_colorsrust-analyzer cargo palette 0.7.6 named/build_colors().(&mut writer); |
| 10 | } |
| 11 | |
| 12 | #[cfg(feature = "named")] |
| 13 | pub fn build_colorsrust-analyzer cargo palette 0.7.6 named/build_colors().(writer: &mut Filerust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/File#) { |
| 14 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::{BufReadrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/BufRead#, BufReaderrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/buffered/bufreader/BufReader#, Writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#}; |
| 15 | |
| 16 | let reader = |
| 17 | BufReaderrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/buffered/bufreader/BufReader#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/buffered/bufreader/impl#[`BufReader<R>`]new().(Filerust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/File#::openrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[File]open().("build/svg_colors.txt").expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("could not open svg_colors.txt")); |
| 18 | let mut entries = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![]; |
| 19 | |
| 20 | for line in reader.linesrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/BufRead#lines().() { |
| 21 | let line = line.unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 22 | let mut parts = line.splitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]split().('\t'); |
| 23 | let name = parts.nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/iter/impl#[`Split<'a, P>`][Iterator]next().().expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]expect().("couldn't get the color name"); |
| 24 | let mut rgb = parts |
| 25 | .nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/iter/impl#[`Split<'a, P>`][Iterator]next().() |
| 26 | .unwrap_or_elserust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or_else().(|| panicrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/panic!!("couldn't get color for {}", name)) |
| 27 | .splitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]split().(", "); |
| 28 | let red: u8 = rgb |
| 29 | .nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/iter/impl#[`Split<'a, P>`][Iterator]next().() |
| 30 | .and_thenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]and_then().(|r| r.trimrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]trim().().parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().().okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]ok().()) |
| 31 | .unwrap_or_elserust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or_else().(|| panicrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/panic!!("couldn't get red for {}", name)); |
| 32 | let green: u8 = rgb |
| 33 | .nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/iter/impl#[`Split<'a, P>`][Iterator]next().() |
| 34 | .and_thenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]and_then().(|r| r.trimrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]trim().().parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().().okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]ok().()) |
| 35 | .unwrap_or_elserust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or_else().(|| panicrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/panic!!("couldn't get green for {}", name)); |
| 36 | let blue: u8 = rgb |
| 37 | .nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/iter/impl#[`Split<'a, P>`][Iterator]next().() |
| 38 | .and_thenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]and_then().(|r| r.trimrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]trim().().parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().().okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]ok().()) |
| 39 | .unwrap_or_elserust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or_else().(|| panicrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/panic!!("couldn't get blue for {}", name)); |
| 40 | |
| 41 | writelnrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/writeln!!(writer, "\n///<div style=\"display: inline-block; width: 3em; height: 1em; border: 1px solid black; background: {0};\"></div>", name).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 42 | writelnrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/writeln!!( |
| 43 | writer, |
| 44 | "pub const {}: crate::rgb::Srgb<u8> = crate::rgb::Srgb::new({}, {}, {});", |
| 45 | name.to_uppercaserust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str]to_uppercase().(), |
| 46 | red, |
| 47 | green, |
| 48 | blue |
| 49 | ) |
| 50 | .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 51 | |
| 52 | entries.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().((name.to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().(), name.to_uppercaserust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str]to_uppercase().())); |
| 53 | } |
| 54 | |
| 55 | gen_from_strrust-analyzer cargo palette 0.7.6 named/gen_from_str().(writer, &entries) |
| 56 | } |
| 57 | |
| 58 | #[cfg(feature = "named_from_str")] |
| 59 | fn gen_from_strrust-analyzer cargo palette 0.7.6 named/gen_from_str().(writer: &mut Filerust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/File#, entries: &[(Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#)]) { |
| 60 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#; |
| 61 | |
| 62 | writer |
| 63 | .write_allrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#write_all().( |
| 64 | "static COLORS: ::phf::Map<&'static str, crate::rgb::Srgb<u8>> = phf::phf_map! {\n" |
| 65 | .as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().(), |
| 66 | ) |
| 67 | .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 68 | |
| 69 | for (key, value) in entries { |
| 70 | writelnrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/writeln!!(writer, " \"{}\" => {},", key, value).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 71 | } |
| 72 | |
| 73 | writer.write_allrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#write_all().("};\n".as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().()).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 74 | } |
| 75 | |
| 76 | #[cfg(not(feature = "named"))] |
| 77 | pub fn build_colors(_writer: &mut Filerust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/File#) {} |
| 78 | |
| 79 | #[allow(unused)] |
| 80 | #[cfg(not(feature = "named_from_str"))] |
| 81 | fn gen_from_str(_writer: &mut Filerust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/File#, _entries: &[(Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#)]) {} |