File tree Expand file tree Collapse file tree 1 file changed +33
-7
lines changed
Expand file tree Collapse file tree 1 file changed +33
-7
lines changed Original file line number Diff line number Diff line change 22
33## Usage
44
5- Add ` json-color ` to your Cargo.toml as usual, and then import and call the ` colorize_json_string ` function:
5+ Add ` json-color ` to your Cargo.toml as usual.
6+
7+ ### Examples
8+
9+ If you don't care about the specific colors used:
610
711``` rust
812extern crate json_color;
913
10- use json_color :: colorize_json_str
11-
12- ...
14+ use json_color :: Colorizer ;
1315
14- if let Ok (colored_json) = colorize_json_str("{ \"foo\": [1, 2. 0, false, null] }") {
15- println! ("{}", colored_json);
16+ fn main () {
17+ let colorizer = Colorizer :: arbitrary ();
18+
19+ if let Some (json_str ) = colorizer . colorize_json_str (" { \ " foo\ " : [1, 2.0, false, null] }" ) {
20+ println! (" {}" , json_str );
21+ }
1622}
1723```
1824
19- That's it!
25+ If you want to pick specific colors to use:
26+
27+ ``` rust
28+ extern crate json_color;
29+
30+ use json_color :: {Colorizer , Color };
31+
32+ fn main () {
33+ let colorizer = Colorizer :: new ()
34+ . null (Color :: Cyan )
35+ . boolean (Color :: Yellow )
36+ . number (Color :: Magenta )
37+ . string (Color :: Green )
38+ . key (Color :: Blue )
39+ . build ();
40+
41+ if let Some (json_str ) = colorizer . colorize_json_str (" { \ " foo\ " : [1, 2.0, false, null] }" ) {
42+ println! (" {}" , json_str );
43+ }
44+ }
45+ ```
2046
2147## Documentation
2248
You can’t perform that action at this time.
0 commit comments