Debian Codegraph @

src/customcolors.rs

raw symbols ◀ ▶ SCIP
1 Debian patch touch this file
1 /// Custom color structure, it will generate a true color in the result
2 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy:, Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:)]
3 pub struct CustomColorrust-analyzer cargo colored 3.1.1 customcolors/CustomColor# {
4 /// Red
5 pub rrust-analyzer cargo colored 3.1.1 customcolors/CustomColor#r.: u8,
6 /// Green
7 pub grust-analyzer cargo colored 3.1.1 customcolors/CustomColor#g.: u8,
8 /// Blue
9 pub brust-analyzer cargo colored 3.1.1 customcolors/CustomColor#b.: u8,
10 }
11
12 /// This only makes custom color creation easier.
13 impl CustomColorrust-analyzer cargo colored 3.1.1 customcolors/CustomColor# {
14 /// Create a new custom color
15 #[must_use]
16 pub const fn newrust-analyzer cargo colored 3.1.1 customcolors/impl#[CustomColor]new().(r: u8, g: u8, b: u8) -> Selfrust-analyzer cargo colored 3.1.1 customcolors/impl#[CustomColor] {
17 Selfrust-analyzer cargo colored 3.1.1 customcolors/impl#[CustomColor] { rrust-analyzer cargo colored 3.1.1 customcolors/CustomColor#r., grust-analyzer cargo colored 3.1.1 customcolors/CustomColor#g., brust-analyzer cargo colored 3.1.1 customcolors/CustomColor#b. }
18 }
19 }
20
21 impl Fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/From#<(u8, u8, u8)> for CustomColorrust-analyzer cargo colored 3.1.1 customcolors/CustomColor# {
22 fn fromrust-analyzer cargo colored 3.1.1 customcolors/impl#[CustomColor][`From<(u8, u8, u8)>`]from().((r, g, b): (u8, u8, u8)) -> Selfrust-analyzer cargo colored 3.1.1 customcolors/impl#[CustomColor][`From<(u8, u8, u8)>`] {
23 Selfrust-analyzer cargo colored 3.1.1 customcolors/impl#[CustomColor][`From<(u8, u8, u8)>`]::newrust-analyzer cargo colored 3.1.1 customcolors/impl#[CustomColor]new().(r, g, b)
24 }
25 }
26
27 #[cfg(test)]
28 mod testsrust-analyzer cargo colored 3.1.1 customcolors/tests/ {
29 use craterust-analyzer cargo colored 3.1.1 crate/::*;
30 #[cfg_attr(feature = "no-color", ignore)]
31 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
•32 #[ignore]
33 fn mainrust-analyzer cargo colored 3.1.1 customcolors/tests/main().() {
34 let my_color = CustomColorrust-analyzer cargo colored 3.1.1 customcolors/CustomColor#::newrust-analyzer cargo colored 3.1.1 customcolors/impl#[CustomColor]new().(0, 120, 120);
35 instarust-analyzer cargo insta 1.46.1 crate/::assert_snapshotrust-analyzer cargo insta 1.46.1 macros/assert_snapshot!!("Greetings from Ukraine".custom_colorrust-analyzer cargo colored 3.1.1 Colorize#custom_color().(my_color));
36 }
37
38 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
39 fn from_tuplerust-analyzer cargo colored 3.1.1 customcolors/tests/from_tuple().() {
40 let tuple = (1u8, 255u8, 0u8);
41 let cc = CustomColorrust-analyzer cargo colored 3.1.1 customcolors/CustomColor#::fromrust-analyzer cargo colored 3.1.1 customcolors/impl#[CustomColor][`From<(u8, u8, u8)>`]from().(tuple);
42
43 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(cc.rrust-analyzer cargo colored 3.1.1 customcolors/CustomColor#r., tuple.0);
44 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(cc.grust-analyzer cargo colored 3.1.1 customcolors/CustomColor#g., tuple.1);
45 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(cc.brust-analyzer cargo colored 3.1.1 customcolors/CustomColor#b., tuple.2);
46 }
47 }