| 1 | //!colored_json crate to output colored serde json with ANSI terminal escape codes |
| 2 | //! |
| 3 | //!# Examples |
| 4 | //! |
| 5 | //!For everything, which implements `AsRef<str>` |
| 6 | //! |
| 7 | //!```rust |
| 8 | //! use colored_json::prelude::*; |
| 9 | //! |
| 10 | //! # fn main() -> Result<(), Box<dyn std::error::Error>> { |
| 11 | //! println!( |
| 12 | //! "{}", |
| 13 | //! r#"{ |
| 14 | //! "array": [ |
| 15 | //! "ele1", |
| 16 | //! "ele2" |
| 17 | //! ], |
| 18 | //! "float": 3.1415926, |
| 19 | //! "integer": 4398798674962568, |
| 20 | //! "string": "string" |
| 21 | //! } |
| 22 | //! "#.to_colored_json_auto()? |
| 23 | //! ); |
| 24 | //! # Ok(()) |
| 25 | //! # } |
| 26 | //!``` |
| 27 | //! |
| 28 | //!or for serde_json::Value |
| 29 | //! |
| 30 | //!```rust |
| 31 | //! use serde_json::{json, Value}; |
| 32 | //! use colored_json::to_colored_json_auto; |
| 33 | //! |
| 34 | //! # fn main() -> Result<(), Box<dyn std::error::Error>> { |
| 35 | //! let val : Value = json!({ |
| 36 | //! "name": "John Doe", |
| 37 | //! "age": 43, |
| 38 | //! "phones": [ |
| 39 | //! "+44 1234567", |
| 40 | //! "+44 2345678" |
| 41 | //! ] |
| 42 | //! }); |
| 43 | //! let s = to_colored_json_auto(&val)?; |
| 44 | //! println!("{}", s); |
| 45 | //! # Ok(()) |
| 46 | //! # } |
| 47 | //!``` |
| 48 | //! |
| 49 | //!With a custom color style: |
| 50 | //! |
| 51 | //!```rust |
| 52 | //! use colored_json::prelude::*; |
| 53 | //! use colored_json::{Color, Style, Styler}; |
| 54 | //! |
| 55 | //! # fn main() -> Result<(), Box<dyn std::error::Error>> { |
| 56 | //! println!( |
| 57 | //! "{}", |
| 58 | //! r#"{ |
| 59 | //! "array": [ |
| 60 | //! "ele1", |
| 61 | //! "ele2" |
| 62 | //! ], |
| 63 | //! "float": 3.1415926, |
| 64 | //! "integer": 4398798674962568, |
| 65 | //! "string": "string" |
| 66 | //! } |
| 67 | //! "#.to_colored_json_with_styler( |
| 68 | //! ColorMode::default().eval(), |
| 69 | //! Styler { |
| 70 | //! key: Color::Green.foreground(), |
| 71 | //! string_value: Color::Blue.bold(), |
| 72 | //! integer_value: Color::Magenta.bold(), |
| 73 | //! float_value: Color::Magenta.italic(), |
| 74 | //! object_brackets: Color::Yellow.bold(), |
| 75 | //! array_brackets: Color::Cyan.bold(), |
| 76 | //! ..Default::default() |
| 77 | //! })? |
| 78 | //! ); |
| 79 | //! Ok(()) |
| 80 | //! # } |
| 81 | //!``` |
| 82 | //! |
| 83 | //! |
| 84 | //!```rust |
| 85 | //! use serde_json::json; |
| 86 | //! |
| 87 | //! use colored_json::{ColoredFormatter, CompactFormatter, Color, Styler, Style}; |
| 88 | //! |
| 89 | //! # fn main() -> Result<(), Box<dyn std::error::Error>> { |
| 90 | //! let f = ColoredFormatter::with_styler( |
| 91 | //! CompactFormatter {}, |
| 92 | //! Styler { |
| 93 | //! key: Color::Green.foreground(), |
| 94 | //! string_value: Color::Blue.bold(), |
| 95 | //! ..Default::default() |
| 96 | //! }, |
| 97 | //! ); |
| 98 | //! |
| 99 | //! println!( |
| 100 | //! "{}", |
| 101 | //! f.clone().to_colored_json_auto(&json!({ |
| 102 | //! "name": "John Doe", |
| 103 | //! "age": 43, |
| 104 | //! "phones": [ |
| 105 | //! "+44 1234567", |
| 106 | //! "+44 2345678" |
| 107 | //! ] |
| 108 | //! }))? |
| 109 | //! ); |
| 110 | //! |
| 111 | //! println!( |
| 112 | //! "{}", |
| 113 | //! f.to_colored_json_auto(&json!({ |
| 114 | //! "name":"John", "age":31, "city":"New York" |
| 115 | //! }))? |
| 116 | //! ); |
| 117 | //! # Ok(()) |
| 118 | //! # } |
| 119 | //!``` |
| 120 | |
| 121 | use serderust-analyzer cargo serde 1.0.144 crate/::Serializerust-analyzer cargo serde 1.0.144 ser/Serialize#; |
| 122 | use serde_jsonrust-analyzer cargo serde_json 1.0.85 crate/::serrust-analyzer cargo serde_json 1.0.85 ser/::Formatterrust-analyzer cargo serde_json 1.0.85 ser/Formatter#; |
| 123 | use serde_jsonrust-analyzer cargo serde_json 1.0.85 crate/::valuerust-analyzer cargo serde_json 1.0.85 value/::Valuerust-analyzer cargo serde_json 1.0.85 value/Value#; |
| 124 | use 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/::var_osrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/var_os().; |
| 125 | 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/::{selfrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/, IsTerminalrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/stdio/IsTerminal#}; |
| 126 | |
| 127 | pub use serde_jsonrust-analyzer cargo serde_json 1.0.85 crate/::serrust-analyzer cargo serde_json 1.0.85 ser/::{CompactFormatterrust-analyzer cargo serde_json 1.0.85 ser/CompactFormatter#, PrettyFormatterrust-analyzer cargo serde_json 1.0.85 ser/PrettyFormatter#}; |
| 128 | pub use yansirust-analyzer cargo yansi 1.0.1 crate/::{Colorrust-analyzer cargo yansi 1.0.1 color/Color#, Paintrust-analyzer cargo yansi 1.0.1 paint/Paint#, Stylerust-analyzer cargo yansi 1.0.1 style/Style#}; |
| 129 | |
| 130 | pub mod preluderust-analyzer cargo colored_json 5.0.0 prelude/ { |
| 131 | pub use craterust-analyzer cargo colored_json 5.0.0 crate/::ColorModerust-analyzer cargo colored_json 5.0.0 ColorMode#; |
| 132 | pub use craterust-analyzer cargo colored_json 5.0.0 crate/::ToColoredJsonrust-analyzer cargo colored_json 5.0.0 ToColoredJson#; |
| 133 | } |
| 134 | |
| 135 | /// Styler lets you define the look of the colored json output |
| 136 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy:)] |
| 137 | pub struct Stylerrust-analyzer cargo colored_json 5.0.0 Styler# { |
| 138 | /// style of object brackets |
| 139 | pub object_bracketsrust-analyzer cargo colored_json 5.0.0 Styler#object_brackets.: Stylerust-analyzer cargo yansi 1.0.1 style/Style#, |
| 140 | /// style of object colons |
| 141 | pub object_colonrust-analyzer cargo colored_json 5.0.0 Styler#object_colon.: Stylerust-analyzer cargo yansi 1.0.1 style/Style#, |
| 142 | /// style of array brackets |
| 143 | pub array_bracketsrust-analyzer cargo colored_json 5.0.0 Styler#array_brackets.: Stylerust-analyzer cargo yansi 1.0.1 style/Style#, |
| 144 | /// style of object |
| 145 | pub keyrust-analyzer cargo colored_json 5.0.0 Styler#key.: Stylerust-analyzer cargo yansi 1.0.1 style/Style#, |
| 146 | /// style of string values |
| 147 | pub string_valuerust-analyzer cargo colored_json 5.0.0 Styler#string_value.: Stylerust-analyzer cargo yansi 1.0.1 style/Style#, |
| 148 | /// style of integer values |
| 149 | pub integer_valuerust-analyzer cargo colored_json 5.0.0 Styler#integer_value.: Stylerust-analyzer cargo yansi 1.0.1 style/Style#, |
| 150 | /// style of float values |
| 151 | pub float_valuerust-analyzer cargo colored_json 5.0.0 Styler#float_value.: Stylerust-analyzer cargo yansi 1.0.1 style/Style#, |
| 152 | /// style of bool values |
| 153 | pub bool_valuerust-analyzer cargo colored_json 5.0.0 Styler#bool_value.: Stylerust-analyzer cargo yansi 1.0.1 style/Style#, |
| 154 | /// style of the `nil` value |
| 155 | pub nil_valuerust-analyzer cargo colored_json 5.0.0 Styler#nil_value.: Stylerust-analyzer cargo yansi 1.0.1 style/Style#, |
| 156 | /// should the quotation get the style of the inner string/key? |
| 157 | pub string_include_quotationrust-analyzer cargo colored_json 5.0.0 Styler#string_include_quotation.: bool, |
| 158 | } |
| 159 | |
| 160 | /// Default style resembling the `jq` style |
| 161 | impl Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default# for Stylerrust-analyzer cargo colored_json 5.0.0 Styler# { |
| 162 | fn defaultrust-analyzer cargo colored_json 5.0.0 impl#[Styler][Default]default().() -> Stylerrust-analyzer cargo colored_json 5.0.0 Styler# { |
| 163 | Stylerrust-analyzer cargo colored_json 5.0.0 Styler# { |
| 164 | object_bracketsrust-analyzer cargo colored_json 5.0.0 Styler#object_brackets.: Stylerust-analyzer cargo yansi 1.0.1 style/Style#::newrust-analyzer cargo yansi 1.0.1 style/impl#[Style]new().().boldrust-analyzer cargo yansi 1.0.1 style/impl#[Style]bold().(), |
| 165 | object_colonrust-analyzer cargo colored_json 5.0.0 Styler#object_colon.: Stylerust-analyzer cargo yansi 1.0.1 style/Style#::newrust-analyzer cargo yansi 1.0.1 style/impl#[Style]new().(), |
| 166 | array_bracketsrust-analyzer cargo colored_json 5.0.0 Styler#array_brackets.: Stylerust-analyzer cargo yansi 1.0.1 style/Style#::newrust-analyzer cargo yansi 1.0.1 style/impl#[Style]new().().boldrust-analyzer cargo yansi 1.0.1 style/impl#[Style]bold().(), |
| 167 | keyrust-analyzer cargo colored_json 5.0.0 Styler#key.: Colorrust-analyzer cargo yansi 1.0.1 color/Color#::Bluerust-analyzer cargo yansi 1.0.1 color/Color#Blue#.boldrust-analyzer cargo yansi 1.0.1 color/impl#[Color]bold().(), |
| 168 | string_valuerust-analyzer cargo colored_json 5.0.0 Styler#string_value.: Colorrust-analyzer cargo yansi 1.0.1 color/Color#::Greenrust-analyzer cargo yansi 1.0.1 color/Color#Green#.foregroundrust-analyzer cargo yansi 1.0.1 color/impl#[Color]foreground().(), |
| 169 | integer_valuerust-analyzer cargo colored_json 5.0.0 Styler#integer_value.: Stylerust-analyzer cargo yansi 1.0.1 style/Style#::newrust-analyzer cargo yansi 1.0.1 style/impl#[Style]new().(), |
| 170 | float_valuerust-analyzer cargo colored_json 5.0.0 Styler#float_value.: Stylerust-analyzer cargo yansi 1.0.1 style/Style#::newrust-analyzer cargo yansi 1.0.1 style/impl#[Style]new().(), |
| 171 | bool_valuerust-analyzer cargo colored_json 5.0.0 Styler#bool_value.: Stylerust-analyzer cargo yansi 1.0.1 style/Style#::newrust-analyzer cargo yansi 1.0.1 style/impl#[Style]new().(), |
| 172 | nil_valuerust-analyzer cargo colored_json 5.0.0 Styler#nil_value.: Stylerust-analyzer cargo yansi 1.0.1 style/Style#::newrust-analyzer cargo yansi 1.0.1 style/impl#[Style]new().().bright_blackrust-analyzer cargo yansi 1.0.1 style/impl#[Style]bright_black().().boldrust-analyzer cargo yansi 1.0.1 style/impl#[Style]bold().(), |
| 173 | string_include_quotationrust-analyzer cargo colored_json 5.0.0 Styler#string_include_quotation.: true, |
| 174 | } |
| 175 | } |
| 176 | } |
| 177 | |
| 178 | /// `ColoredFormatter` decorates a `Formatter` with color defined in `Styler` |
| 179 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:)] |
| 180 | pub struct ColoredFormatterrust-analyzer cargo colored_json 5.0.0 ColoredFormatter#<F> |
| 181 | where |
| 182 | F: Formatterrust-analyzer cargo serde_json 1.0.85 ser/Formatter#, |
| 183 | { |
| 184 | formatterrust-analyzer cargo colored_json 5.0.0 ColoredFormatter#formatter.: F, |
| 185 | stylerrust-analyzer cargo colored_json 5.0.0 ColoredFormatter#styler.: Stylerrust-analyzer cargo colored_json 5.0.0 Styler#, |
| 186 | in_object_keyrust-analyzer cargo colored_json 5.0.0 ColoredFormatter#in_object_key.: bool, |
| 187 | } |
| 188 | |
| 189 | impl<F> ColoredFormatterrust-analyzer cargo colored_json 5.0.0 ColoredFormatter#<F> |
| 190 | where |
| 191 | F: Formatterrust-analyzer cargo serde_json 1.0.85 ser/Formatter#, |
| 192 | { |
| 193 | pub fn newrust-analyzer cargo colored_json 5.0.0 impl#[`ColoredFormatter<F>`]new().(formatter: F) -> Selfrust-analyzer cargo colored_json 5.0.0 impl#[`ColoredFormatter<F>`] { |
| 194 | ColoredFormatterrust-analyzer cargo colored_json 5.0.0 ColoredFormatter# { |
| 195 | formatterrust-analyzer cargo colored_json 5.0.0 ColoredFormatter#formatter., |
| 196 | stylerrust-analyzer cargo colored_json 5.0.0 ColoredFormatter#styler.: Stylerrust-analyzer cargo colored_json 5.0.0 Styler#::defaultrust-analyzer cargo colored_json 5.0.0 impl#[Styler][Default]default().(), |
| 197 | in_object_keyrust-analyzer cargo colored_json 5.0.0 ColoredFormatter#in_object_key.: false, |
| 198 | } |
| 199 | } |
| 200 | |
| 201 | pub fn with_stylerrust-analyzer cargo colored_json 5.0.0 impl#[`ColoredFormatter<F>`]with_styler().(formatter: F, styler: Stylerrust-analyzer cargo colored_json 5.0.0 Styler#) -> Selfrust-analyzer cargo colored_json 5.0.0 impl#[`ColoredFormatter<F>`] { |
| 202 | ColoredFormatterrust-analyzer cargo colored_json 5.0.0 ColoredFormatter# { |
| 203 | formatterrust-analyzer cargo colored_json 5.0.0 ColoredFormatter#formatter., |
| 204 | stylerrust-analyzer cargo colored_json 5.0.0 ColoredFormatter#styler., |
| 205 | in_object_keyrust-analyzer cargo colored_json 5.0.0 ColoredFormatter#in_object_key.: false, |
| 206 | } |
| 207 | } |
| 208 | |
| 209 | #[allow(clippy::wrong_self_convention)] |
| 210 | pub fn to_colored_json_autorust-analyzer cargo colored_json 5.0.0 impl#[`ColoredFormatter<F>`]to_colored_json_auto().<T>(self, value: &T) -> serde_jsonrust-analyzer cargo serde_json 1.0.85 crate/::Resultrust-analyzer cargo serde_json 1.0.85 error/Result#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#> |
| 211 | where |
| 212 | T: Serializerust-analyzer cargo serde 1.0.144 ser/Serialize#, |
| 213 | { |
| 214 | self.to_colored_jsonrust-analyzer cargo colored_json 5.0.0 impl#[`ColoredFormatter<F>`]to_colored_json().(value, ColorModerust-analyzer cargo colored_json 5.0.0 ColorMode#::Autorust-analyzer cargo colored_json 5.0.0 ColorMode#Auto#(Outputrust-analyzer cargo colored_json 5.0.0 Output#::StdOutrust-analyzer cargo colored_json 5.0.0 Output#StdOut#)) |
| 215 | } |
| 216 | |
| 217 | #[allow(clippy::wrong_self_convention)] |
| 218 | pub fn to_colored_jsonrust-analyzer cargo colored_json 5.0.0 impl#[`ColoredFormatter<F>`]to_colored_json().<T>(self, value: &T, mode: ColorModerust-analyzer cargo colored_json 5.0.0 ColorMode#) -> serde_jsonrust-analyzer cargo serde_json 1.0.85 crate/::Resultrust-analyzer cargo serde_json 1.0.85 error/Result#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#> |
| 219 | where |
| 220 | T: Serializerust-analyzer cargo serde 1.0.144 ser/Serialize#, |
| 221 | { |
| 222 | let mut writer: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8> = Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::with_capacityrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]with_capacity().(128); |
| 223 | |
| 224 | self.write_colored_jsonrust-analyzer cargo colored_json 5.0.0 impl#[`ColoredFormatter<F>`]write_colored_json().(value, &mut writer, mode)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 225 | |
| 226 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::from_utf8_lossyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]from_utf8_lossy().(&writer).to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()) |
| 227 | } |
| 228 | |
| 229 | pub fn write_colored_jsonrust-analyzer cargo colored_json 5.0.0 impl#[`ColoredFormatter<F>`]write_colored_json().<W, T>( |
| 230 | self, |
| 231 | value: &T, |
| 232 | writer: &mut W, |
| 233 | mode: ColorModerust-analyzer cargo colored_json 5.0.0 ColorMode#, |
| 234 | ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), serde_jsonrust-analyzer cargo serde_json 1.0.85 crate/::Errorrust-analyzer cargo serde_json 1.0.85 error/Error#> |
| 235 | where |
| 236 | W: 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#, |
| 237 | T: Serializerust-analyzer cargo serde 1.0.144 ser/Serialize#, |
| 238 | { |
| 239 | if mode.use_colorrust-analyzer cargo colored_json 5.0.0 impl#[ColorMode]use_color().() { |
| 240 | let mut serializer = serde_jsonrust-analyzer cargo serde_json 1.0.85 crate/::Serializerrust-analyzer cargo serde_json 1.0.85 ser/Serializer#::with_formatterrust-analyzer cargo serde_json 1.0.85 ser/impl#[`Serializer<W, F>`]with_formatter().(writer, self); |
| 241 | value.serializerust-analyzer cargo serde 1.0.144 ser/Serialize#serialize().(&mut serializer) |
| 242 | } else { |
| 243 | let mut serializer = serde_jsonrust-analyzer cargo serde_json 1.0.85 crate/::Serializerrust-analyzer cargo serde_json 1.0.85 ser/Serializer#::with_formatterrust-analyzer cargo serde_json 1.0.85 ser/impl#[`Serializer<W, F>`]with_formatter().(writer, self.formatterrust-analyzer cargo colored_json 5.0.0 ColoredFormatter#formatter.); |
| 244 | value.serializerust-analyzer cargo serde 1.0.144 ser/Serialize#serialize().(&mut serializer) |
| 245 | } |
| 246 | } |
| 247 | } |
| 248 | |
| 249 | fn coloredrust-analyzer cargo colored_json 5.0.0 colored().<W: ?Sizedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sized#, H>(writer: &mut W, style: Stylerust-analyzer cargo yansi 1.0.1 style/Style#, mut handler: H) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<()> |
| 250 | where |
| 251 | W: 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#, |
| 252 | H: FnMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnMut#(&mut Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8>) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<()>, |
| 253 | { |
| 254 | let mut w: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8> = Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::with_capacityrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]with_capacity().(128); |
| 255 | handler(&mut w)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 256 | |
| 257 | if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().w.is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]is_empty().() { |
| 258 | let s = Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::from_utf8_lossyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]from_utf8_lossy().(&w); |
| 259 | writer.write_allrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#write_all().(s.paintrust-analyzer cargo yansi 1.0.1 paint/Paint#paint().(style).to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().().as_bytesrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]as_bytes().())?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 260 | } |
| 261 | |
| 262 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 263 | } |
| 264 | |
| 265 | impl<F> Formatterrust-analyzer cargo serde_json 1.0.85 ser/Formatter# for ColoredFormatterrust-analyzer cargo colored_json 5.0.0 ColoredFormatter#<F> |
| 266 | where |
| 267 | F: Formatterrust-analyzer cargo serde_json 1.0.85 ser/Formatter#, |
| 268 | { |
| 269 | fn write_nullrust-analyzer cargo colored_json 5.0.0 impl#[`ColoredFormatter<F>`][Formatter]write_null().<W: ?Sizedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sized#>(&mut self, writer: &mut W) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<()> |
| 270 | where |
| 271 | W: 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#, |
| 272 | { |
| 273 | coloredrust-analyzer cargo colored_json 5.0.0 colored().(writer, self.stylerrust-analyzer cargo colored_json 5.0.0 ColoredFormatter#styler..nil_valuerust-analyzer cargo colored_json 5.0.0 Styler#nil_value., |w| { |
| 274 | self.formatterrust-analyzer cargo colored_json 5.0.0 ColoredFormatter#formatter..write_nullrust-analyzer cargo serde_json 1.0.85 ser/Formatter#write_null().(w) |
| 275 | }) |
| 276 | } |
| 277 | |
| 278 | fn write_boolrust-analyzer cargo colored_json 5.0.0 impl#[`ColoredFormatter<F>`][Formatter]write_bool().<W: ?Sizedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sized#>(&mut self, writer: &mut W, value: bool) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<()> |
| 279 | where |
| 280 | W: 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#, |
| 281 | { |
| 282 | coloredrust-analyzer cargo colored_json 5.0.0 colored().(writer, self.stylerrust-analyzer cargo colored_json 5.0.0 ColoredFormatter#styler..bool_valuerust-analyzer cargo colored_json 5.0.0 Styler#bool_value., |w| { |
| 283 | self.formatterrust-analyzer cargo colored_json 5.0.0 ColoredFormatter#formatter..write_boolrust-analyzer cargo serde_json 1.0.85 ser/Formatter#write_bool().(w, value) |
| 284 | }) |
| 285 | } |
| 286 | |
| 287 | fn write_i8rust-analyzer cargo colored_json 5.0.0 impl#[`ColoredFormatter<F>`][Formatter]write_i8().<W: ?Sizedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sized#>(&mut self, writer: &mut W, value: i8) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<()> |
| 288 | where |
| 289 | W: 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#, |
| 290 | { |
| 291 | coloredrust-analyzer cargo colored_json 5.0.0 colored().(writer, self.stylerrust-analyzer cargo colored_json 5.0.0 ColoredFormatter#styler..integer_valuerust-analyzer cargo colored_json 5.0.0 Styler#integer_value., |w| { |
| 292 | self.formatterrust-analyzer cargo colored_json 5.0.0 ColoredFormatter#formatter..write_i8rust-analyzer cargo serde_json 1.0.85 ser/Formatter#write_i8().(w, value) |
| 293 | }) |
| 294 | } |
| 295 | |
| 296 | fn write_i16rust-analyzer cargo colored_json 5.0.0 impl#[`ColoredFormatter<F>`][Formatter]write_i16().<W: ?Sizedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sized#>(&mut self, writer: &mut W, value: i16) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<()> |
| 297 | where |
| 298 | W: 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#, |
| 299 | { |
| 300 | coloredrust-analyzer cargo colored_json 5.0.0 colored().(writer, self.stylerrust-analyzer cargo colored_json 5.0.0 ColoredFormatter#styler..integer_valuerust-analyzer cargo colored_json 5.0.0 Styler#integer_value., |w| { |
| 301 | self.formatterrust-analyzer cargo colored_json 5.0.0 ColoredFormatter#formatter..write_i16rust-analyzer cargo serde_json 1.0.85 ser/Formatter#write_i16().(w, value) |
| 302 | }) |
| 303 | } |
| 304 | |
| 305 | fn write_i32rust-analyzer cargo colored_json 5.0.0 impl#[`ColoredFormatter<F>`][Formatter]write_i32().<W: ?Sizedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sized#>(&mut self, writer: &mut W, value: i32) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<()> |
| 306 | where |
| 307 | W: 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#, |
| 308 | { |
| 309 | coloredrust-analyzer cargo colored_json 5.0.0 colored().(writer, self.stylerrust-analyzer cargo colored_json 5.0.0 ColoredFormatter#styler..integer_valuerust-analyzer cargo colored_json 5.0.0 Styler#integer_value., |w| { |
| 310 | self.formatterrust-analyzer cargo colored_json 5.0.0 ColoredFormatter#formatter..write_i32rust-analyzer cargo serde_json 1.0.85 ser/Formatter#write_i32().(w, value) |
| 311 | }) |
| 312 | } |
| 313 | |
| 314 | fn write_i64rust-analyzer cargo colored_json 5.0.0 impl#[`ColoredFormatter<F>`][Formatter]write_i64().<W: ?Sizedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sized#>(&mut self, writer: &mut W, value: i64) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<()> |
| 315 | where |
| 316 | W: 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#, |
| 317 | { |
| 318 | coloredrust-analyzer cargo colored_json 5.0.0 colored().(writer, self.stylerrust-analyzer cargo colored_json 5.0.0 ColoredFormatter#styler..integer_valuerust-analyzer cargo colored_json 5.0.0 Styler#integer_value., |w| { |
| 319 | self.formatterrust-analyzer cargo colored_json 5.0.0 ColoredFormatter#formatter..write_i64rust-analyzer cargo serde_json 1.0.85 ser/Formatter#write_i64().(w, value) |
| 320 | }) |
| 321 | } |
| 322 | |
| 323 | fn write_u8rust-analyzer cargo colored_json 5.0.0 impl#[`ColoredFormatter<F>`][Formatter]write_u8().<W: ?Sizedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sized#>(&mut self, writer: &mut W, value: u8) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<()> |
| 324 | where |
| 325 | W: 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#, |
| 326 | { |
| 327 | coloredrust-analyzer cargo colored_json 5.0.0 colored().(writer, self.stylerrust-analyzer cargo colored_json 5.0.0 ColoredFormatter#styler..integer_valuerust-analyzer cargo colored_json 5.0.0 Styler#integer_value., |w| { |
| 328 | self.formatterrust-analyzer cargo colored_json 5.0.0 ColoredFormatter#formatter..write_u8rust-analyzer cargo serde_json 1.0.85 ser/Formatter#write_u8().(w, value) |
| 329 | }) |
| 330 | } |
| 331 | |
| 332 | fn write_u16rust-analyzer cargo colored_json 5.0.0 impl#[`ColoredFormatter<F>`][Formatter]write_u16().<W: ?Sizedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sized#>(&mut self, writer: &mut W, value: u16) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<()> |
| 333 | where |
| 334 | W: 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#, |
| 335 | { |
| 336 | coloredrust-analyzer cargo colored_json 5.0.0 colored().(writer, self.stylerrust-analyzer cargo colored_json 5.0.0 ColoredFormatter#styler..integer_valuerust-analyzer cargo colored_json 5.0.0 Styler#integer_value., |w| { |
| 337 | self.formatterrust-analyzer cargo colored_json 5.0.0 ColoredFormatter#formatter..write_u16rust-analyzer cargo serde_json 1.0.85 ser/Formatter#write_u16().(w, value) |
| 338 | }) |
| 339 | } |
| 340 | |
| 341 | fn write_u32rust-analyzer cargo colored_json 5.0.0 impl#[`ColoredFormatter<F>`][Formatter]write_u32().<W: ?Sizedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sized#>(&mut self, writer: &mut W, value: u32) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<()> |
| 342 | where |
| 343 | W: 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#, |
| 344 | { |
| 345 | coloredrust-analyzer cargo colored_json 5.0.0 colored().(writer, self.stylerrust-analyzer cargo colored_json 5.0.0 ColoredFormatter#styler..integer_valuerust-analyzer cargo colored_json 5.0.0 Styler#integer_value., |w| { |
| 346 | self.formatterrust-analyzer cargo colored_json 5.0.0 ColoredFormatter#formatter..write_u32rust-analyzer cargo serde_json 1.0.85 ser/Formatter#write_u32().(w, value) |
| 347 | }) |
| 348 | } |
| 349 | |
| 350 | fn write_u64rust-analyzer cargo colored_json 5.0.0 impl#[`ColoredFormatter<F>`][Formatter]write_u64().<W: ?Sizedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sized#>(&mut self, writer: &mut W, value: u64) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<()> |
| 351 | where |
| 352 | W: 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#, |
| 353 | { |
| 354 | coloredrust-analyzer cargo colored_json 5.0.0 colored().(writer, self.stylerrust-analyzer cargo colored_json 5.0.0 ColoredFormatter#styler..integer_valuerust-analyzer cargo colored_json 5.0.0 Styler#integer_value., |w| { |
| 355 | self.formatterrust-analyzer cargo colored_json 5.0.0 ColoredFormatter#formatter..write_u64rust-analyzer cargo serde_json 1.0.85 ser/Formatter#write_u64().(w, value) |
| 356 | }) |
| 357 | } |
| 358 | |
| 359 | fn write_f32rust-analyzer cargo colored_json 5.0.0 impl#[`ColoredFormatter<F>`][Formatter]write_f32().<W: ?Sizedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sized#>(&mut self, writer: &mut W, value: f32) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<()> |
| 360 | where |
| 361 | W: 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#, |
| 362 | { |
| 363 | coloredrust-analyzer cargo colored_json 5.0.0 colored().(writer, self.stylerrust-analyzer cargo colored_json 5.0.0 ColoredFormatter#styler..float_valuerust-analyzer cargo colored_json 5.0.0 Styler#float_value., |w| { |
| 364 | self.formatterrust-analyzer cargo colored_json 5.0.0 ColoredFormatter#formatter..write_f32rust-analyzer cargo serde_json 1.0.85 ser/Formatter#write_f32().(w, value) |
| 365 | }) |
| 366 | } |
| 367 | |
| 368 | fn write_f64rust-analyzer cargo colored_json 5.0.0 impl#[`ColoredFormatter<F>`][Formatter]write_f64().<W: ?Sizedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sized#>(&mut self, writer: &mut W, value: f64) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<()> |
| 369 | where |
| 370 | W: 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#, |
| 371 | { |
| 372 | coloredrust-analyzer cargo colored_json 5.0.0 colored().(writer, self.stylerrust-analyzer cargo colored_json 5.0.0 ColoredFormatter#styler..float_valuerust-analyzer cargo colored_json 5.0.0 Styler#float_value., |w| { |
| 373 | self.formatterrust-analyzer cargo colored_json 5.0.0 ColoredFormatter#formatter..write_f64rust-analyzer cargo serde_json 1.0.85 ser/Formatter#write_f64().(w, value) |
| 374 | }) |
| 375 | } |
| 376 | |
| 377 | fn write_number_strrust-analyzer cargo colored_json 5.0.0 impl#[`ColoredFormatter<F>`][Formatter]write_number_str().<W: ?Sizedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sized#>(&mut self, writer: &mut W, value: &str) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<()> |
| 378 | where |
| 379 | W: 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#, |
| 380 | { |
| 381 | coloredrust-analyzer cargo colored_json 5.0.0 colored().(writer, self.stylerrust-analyzer cargo colored_json 5.0.0 ColoredFormatter#styler..integer_valuerust-analyzer cargo colored_json 5.0.0 Styler#integer_value., |w| { |
| 382 | self.formatterrust-analyzer cargo colored_json 5.0.0 ColoredFormatter#formatter..write_number_strrust-analyzer cargo serde_json 1.0.85 ser/Formatter#write_number_str().(w, value) |
| 383 | }) |
| 384 | // self.formatter.write_number_str(writer, value) |
| 385 | } |
| 386 | |
| 387 | fn begin_stringrust-analyzer cargo colored_json 5.0.0 impl#[`ColoredFormatter<F>`][Formatter]begin_string().<W: ?Sizedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sized#>(&mut self, writer: &mut W) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<()> |
| 388 | where |
| 389 | W: 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#, |
| 390 | { |
| 391 | if self.stylerrust-analyzer cargo colored_json 5.0.0 ColoredFormatter#styler..string_include_quotationrust-analyzer cargo colored_json 5.0.0 Styler#string_include_quotation. { |
| 392 | let style = if self.in_object_keyrust-analyzer cargo colored_json 5.0.0 ColoredFormatter#in_object_key. { |
| 393 | self.stylerrust-analyzer cargo colored_json 5.0.0 ColoredFormatter#styler..keyrust-analyzer cargo colored_json 5.0.0 Styler#key. |
| 394 | } else { |
| 395 | self.stylerrust-analyzer cargo colored_json 5.0.0 ColoredFormatter#styler..string_valuerust-analyzer cargo colored_json 5.0.0 Styler#string_value. |
| 396 | }; |
| 397 | coloredrust-analyzer cargo colored_json 5.0.0 colored().(writer, style, |w| self.formatterrust-analyzer cargo colored_json 5.0.0 ColoredFormatter#formatter..begin_stringrust-analyzer cargo serde_json 1.0.85 ser/Formatter#begin_string().(w)) |
| 398 | } else { |
| 399 | self.formatterrust-analyzer cargo colored_json 5.0.0 ColoredFormatter#formatter..begin_stringrust-analyzer cargo serde_json 1.0.85 ser/Formatter#begin_string().(writer) |
| 400 | } |
| 401 | } |
| 402 | |
| 403 | fn end_stringrust-analyzer cargo colored_json 5.0.0 impl#[`ColoredFormatter<F>`][Formatter]end_string().<W: ?Sizedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sized#>(&mut self, writer: &mut W) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<()> |
| 404 | where |
| 405 | W: 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#, |
| 406 | { |
| 407 | if self.stylerrust-analyzer cargo colored_json 5.0.0 ColoredFormatter#styler..string_include_quotationrust-analyzer cargo colored_json 5.0.0 Styler#string_include_quotation. { |
| 408 | let style = if self.in_object_keyrust-analyzer cargo colored_json 5.0.0 ColoredFormatter#in_object_key. { |
| 409 | self.stylerrust-analyzer cargo colored_json 5.0.0 ColoredFormatter#styler..keyrust-analyzer cargo colored_json 5.0.0 Styler#key. |
| 410 | } else { |
| 411 | self.stylerrust-analyzer cargo colored_json 5.0.0 ColoredFormatter#styler..string_valuerust-analyzer cargo colored_json 5.0.0 Styler#string_value. |
| 412 | }; |
| 413 | coloredrust-analyzer cargo colored_json 5.0.0 colored().(writer, style, |w| self.formatterrust-analyzer cargo colored_json 5.0.0 ColoredFormatter#formatter..end_stringrust-analyzer cargo serde_json 1.0.85 ser/Formatter#end_string().(w)) |
| 414 | } else { |
| 415 | self.formatterrust-analyzer cargo colored_json 5.0.0 ColoredFormatter#formatter..end_stringrust-analyzer cargo serde_json 1.0.85 ser/Formatter#end_string().(writer) |
| 416 | } |
| 417 | } |
| 418 | |
| 419 | fn write_string_fragmentrust-analyzer cargo colored_json 5.0.0 impl#[`ColoredFormatter<F>`][Formatter]write_string_fragment().<W: ?Sizedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sized#>(&mut self, writer: &mut W, fragment: &str) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<()> |
| 420 | where |
| 421 | W: 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#, |
| 422 | { |
| 423 | let style = if self.in_object_keyrust-analyzer cargo colored_json 5.0.0 ColoredFormatter#in_object_key. { |
| 424 | self.stylerrust-analyzer cargo colored_json 5.0.0 ColoredFormatter#styler..keyrust-analyzer cargo colored_json 5.0.0 Styler#key. |
| 425 | } else { |
| 426 | self.stylerrust-analyzer cargo colored_json 5.0.0 ColoredFormatter#styler..string_valuerust-analyzer cargo colored_json 5.0.0 Styler#string_value. |
| 427 | }; |
| 428 | coloredrust-analyzer cargo colored_json 5.0.0 colored().(writer, style, |w| { |
| 429 | self.formatterrust-analyzer cargo colored_json 5.0.0 ColoredFormatter#formatter..write_string_fragmentrust-analyzer cargo serde_json 1.0.85 ser/Formatter#write_string_fragment().(w, fragment) |
| 430 | }) |
| 431 | } |
| 432 | |
| 433 | fn begin_arrayrust-analyzer cargo colored_json 5.0.0 impl#[`ColoredFormatter<F>`][Formatter]begin_array().<W: ?Sizedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sized#>(&mut self, writer: &mut W) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<()> |
| 434 | where |
| 435 | W: 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#, |
| 436 | { |
| 437 | coloredrust-analyzer cargo colored_json 5.0.0 colored().(writer, self.stylerrust-analyzer cargo colored_json 5.0.0 ColoredFormatter#styler..array_bracketsrust-analyzer cargo colored_json 5.0.0 Styler#array_brackets., |w| { |
| 438 | self.formatterrust-analyzer cargo colored_json 5.0.0 ColoredFormatter#formatter..begin_arrayrust-analyzer cargo serde_json 1.0.85 ser/Formatter#begin_array().(w) |
| 439 | }) |
| 440 | } |
| 441 | |
| 442 | fn end_arrayrust-analyzer cargo colored_json 5.0.0 impl#[`ColoredFormatter<F>`][Formatter]end_array().<W: ?Sizedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sized#>(&mut self, writer: &mut W) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<()> |
| 443 | where |
| 444 | W: 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#, |
| 445 | { |
| 446 | coloredrust-analyzer cargo colored_json 5.0.0 colored().(writer, self.stylerrust-analyzer cargo colored_json 5.0.0 ColoredFormatter#styler..array_bracketsrust-analyzer cargo colored_json 5.0.0 Styler#array_brackets., |w| { |
| 447 | self.formatterrust-analyzer cargo colored_json 5.0.0 ColoredFormatter#formatter..end_arrayrust-analyzer cargo serde_json 1.0.85 ser/Formatter#end_array().(w) |
| 448 | }) |
| 449 | } |
| 450 | |
| 451 | fn begin_array_valuerust-analyzer cargo colored_json 5.0.0 impl#[`ColoredFormatter<F>`][Formatter]begin_array_value().<W: ?Sizedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sized#>(&mut self, writer: &mut W, first: bool) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<()> |
| 452 | where |
| 453 | W: 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#, |
| 454 | { |
| 455 | self.formatterrust-analyzer cargo colored_json 5.0.0 ColoredFormatter#formatter..begin_array_valuerust-analyzer cargo serde_json 1.0.85 ser/Formatter#begin_array_value().(writer, first) |
| 456 | } |
| 457 | |
| 458 | fn end_array_valuerust-analyzer cargo colored_json 5.0.0 impl#[`ColoredFormatter<F>`][Formatter]end_array_value().<W: ?Sizedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sized#>(&mut self, writer: &mut W) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<()> |
| 459 | where |
| 460 | W: 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#, |
| 461 | { |
| 462 | self.formatterrust-analyzer cargo colored_json 5.0.0 ColoredFormatter#formatter..end_array_valuerust-analyzer cargo serde_json 1.0.85 ser/Formatter#end_array_value().(writer) |
| 463 | } |
| 464 | |
| 465 | fn begin_objectrust-analyzer cargo colored_json 5.0.0 impl#[`ColoredFormatter<F>`][Formatter]begin_object().<W: ?Sizedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sized#>(&mut self, writer: &mut W) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<()> |
| 466 | where |
| 467 | W: 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#, |
| 468 | { |
| 469 | coloredrust-analyzer cargo colored_json 5.0.0 colored().(writer, self.stylerrust-analyzer cargo colored_json 5.0.0 ColoredFormatter#styler..object_bracketsrust-analyzer cargo colored_json 5.0.0 Styler#object_brackets., |w| { |
| 470 | self.formatterrust-analyzer cargo colored_json 5.0.0 ColoredFormatter#formatter..begin_objectrust-analyzer cargo serde_json 1.0.85 ser/Formatter#begin_object().(w) |
| 471 | }) |
| 472 | } |
| 473 | |
| 474 | fn end_objectrust-analyzer cargo colored_json 5.0.0 impl#[`ColoredFormatter<F>`][Formatter]end_object().<W: ?Sizedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sized#>(&mut self, writer: &mut W) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<()> |
| 475 | where |
| 476 | W: 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#, |
| 477 | { |
| 478 | coloredrust-analyzer cargo colored_json 5.0.0 colored().(writer, self.stylerrust-analyzer cargo colored_json 5.0.0 ColoredFormatter#styler..object_bracketsrust-analyzer cargo colored_json 5.0.0 Styler#object_brackets., |w| { |
| 479 | self.formatterrust-analyzer cargo colored_json 5.0.0 ColoredFormatter#formatter..end_objectrust-analyzer cargo serde_json 1.0.85 ser/Formatter#end_object().(w) |
| 480 | }) |
| 481 | } |
| 482 | |
| 483 | fn begin_object_keyrust-analyzer cargo colored_json 5.0.0 impl#[`ColoredFormatter<F>`][Formatter]begin_object_key().<W: ?Sizedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sized#>(&mut self, writer: &mut W, first: bool) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<()> |
| 484 | where |
| 485 | W: 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#, |
| 486 | { |
| 487 | self.in_object_keyrust-analyzer cargo colored_json 5.0.0 ColoredFormatter#in_object_key. = true; |
| 488 | self.formatterrust-analyzer cargo colored_json 5.0.0 ColoredFormatter#formatter..begin_object_keyrust-analyzer cargo serde_json 1.0.85 ser/Formatter#begin_object_key().(writer, first) |
| 489 | } |
| 490 | |
| 491 | fn end_object_keyrust-analyzer cargo colored_json 5.0.0 impl#[`ColoredFormatter<F>`][Formatter]end_object_key().<W: ?Sizedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sized#>(&mut self, writer: &mut W) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<()> |
| 492 | where |
| 493 | W: 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#, |
| 494 | { |
| 495 | self.in_object_keyrust-analyzer cargo colored_json 5.0.0 ColoredFormatter#in_object_key. = false; |
| 496 | coloredrust-analyzer cargo colored_json 5.0.0 colored().(writer, self.stylerrust-analyzer cargo colored_json 5.0.0 ColoredFormatter#styler..object_colonrust-analyzer cargo colored_json 5.0.0 Styler#object_colon., |w| { |
| 497 | self.formatterrust-analyzer cargo colored_json 5.0.0 ColoredFormatter#formatter..end_object_keyrust-analyzer cargo serde_json 1.0.85 ser/Formatter#end_object_key().(w) |
| 498 | }) |
| 499 | } |
| 500 | |
| 501 | fn begin_object_valuerust-analyzer cargo colored_json 5.0.0 impl#[`ColoredFormatter<F>`][Formatter]begin_object_value().<W: ?Sizedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sized#>(&mut self, writer: &mut W) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<()> |
| 502 | where |
| 503 | W: 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#, |
| 504 | { |
| 505 | self.in_object_keyrust-analyzer cargo colored_json 5.0.0 ColoredFormatter#in_object_key. = false; |
| 506 | coloredrust-analyzer cargo colored_json 5.0.0 colored().(writer, self.stylerrust-analyzer cargo colored_json 5.0.0 ColoredFormatter#styler..object_colonrust-analyzer cargo colored_json 5.0.0 Styler#object_colon., |w| { |
| 507 | self.formatterrust-analyzer cargo colored_json 5.0.0 ColoredFormatter#formatter..begin_object_valuerust-analyzer cargo serde_json 1.0.85 ser/Formatter#begin_object_value().(w) |
| 508 | }) |
| 509 | } |
| 510 | |
| 511 | fn end_object_valuerust-analyzer cargo colored_json 5.0.0 impl#[`ColoredFormatter<F>`][Formatter]end_object_value().<W: ?Sizedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sized#>(&mut self, writer: &mut W) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<()> |
| 512 | where |
| 513 | W: 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#, |
| 514 | { |
| 515 | self.in_object_keyrust-analyzer cargo colored_json 5.0.0 ColoredFormatter#in_object_key. = false; |
| 516 | self.formatterrust-analyzer cargo colored_json 5.0.0 ColoredFormatter#formatter..end_object_valuerust-analyzer cargo serde_json 1.0.85 ser/Formatter#end_object_value().(writer)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 517 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 518 | } |
| 519 | |
| 520 | fn write_raw_fragmentrust-analyzer cargo colored_json 5.0.0 impl#[`ColoredFormatter<F>`][Formatter]write_raw_fragment().<W: ?Sizedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sized#>(&mut self, writer: &mut W, fragment: &str) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<()> |
| 521 | where |
| 522 | W: 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#, |
| 523 | { |
| 524 | self.formatterrust-analyzer cargo colored_json 5.0.0 ColoredFormatter#formatter..write_raw_fragmentrust-analyzer cargo serde_json 1.0.85 ser/Formatter#write_raw_fragment().(writer, fragment) |
| 525 | } |
| 526 | } |
| 527 | |
| 528 | /// Trait to add json coloring for all `AsRef<str>` like `String` and `&str` |
| 529 | pub trait ToColoredJsonrust-analyzer cargo colored_json 5.0.0 ToColoredJson# { |
| 530 | fn to_colored_json_autorust-analyzer cargo colored_json 5.0.0 ToColoredJson#to_colored_json_auto().(&self) -> serde_jsonrust-analyzer cargo serde_json 1.0.85 crate/::Resultrust-analyzer cargo serde_json 1.0.85 error/Result#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>; |
| 531 | fn to_colored_jsonrust-analyzer cargo colored_json 5.0.0 ToColoredJson#to_colored_json().(&self, mode: ColorModerust-analyzer cargo colored_json 5.0.0 ColorMode#) -> serde_jsonrust-analyzer cargo serde_json 1.0.85 crate/::Resultrust-analyzer cargo serde_json 1.0.85 error/Result#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>; |
| 532 | fn to_colored_json_with_stylerrust-analyzer cargo colored_json 5.0.0 ToColoredJson#to_colored_json_with_styler().( |
| 533 | &self, |
| 534 | mode: ColorModerust-analyzer cargo colored_json 5.0.0 ColorMode#, |
| 535 | styler: Stylerrust-analyzer cargo colored_json 5.0.0 Styler#, |
| 536 | ) -> serde_jsonrust-analyzer cargo serde_json 1.0.85 crate/::Resultrust-analyzer cargo serde_json 1.0.85 error/Result#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>; |
| 537 | fn write_colored_jsonrust-analyzer cargo colored_json 5.0.0 ToColoredJson#write_colored_json().<W>(&self, writer: &mut W) -> serde_jsonrust-analyzer cargo serde_json 1.0.85 crate/::Resultrust-analyzer cargo serde_json 1.0.85 error/Result#<()> |
| 538 | where |
| 539 | W: 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#; |
| 540 | fn write_colored_json_with_moderust-analyzer cargo colored_json 5.0.0 ToColoredJson#write_colored_json_with_mode().<W>( |
| 541 | &self, |
| 542 | writer: &mut W, |
| 543 | mode: ColorModerust-analyzer cargo colored_json 5.0.0 ColorMode#, |
| 544 | ) -> serde_jsonrust-analyzer cargo serde_json 1.0.85 crate/::Resultrust-analyzer cargo serde_json 1.0.85 error/Result#<()> |
| 545 | where |
| 546 | W: 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#; |
| 547 | fn write_colored_json_with_stylerrust-analyzer cargo colored_json 5.0.0 ToColoredJson#write_colored_json_with_styler().<W>( |
| 548 | &self, |
| 549 | writer: &mut W, |
| 550 | mode: ColorModerust-analyzer cargo colored_json 5.0.0 ColorMode#, |
| 551 | styler: Stylerrust-analyzer cargo colored_json 5.0.0 Styler#, |
| 552 | ) -> serde_jsonrust-analyzer cargo serde_json 1.0.85 crate/::Resultrust-analyzer cargo serde_json 1.0.85 error/Result#<()> |
| 553 | where |
| 554 | W: 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#; |
| 555 | } |
| 556 | |
| 557 | impl<S> ToColoredJsonrust-analyzer cargo colored_json 5.0.0 ToColoredJson# for S |
| 558 | where |
| 559 | S: ?Sizedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sized# + AsRefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#<str>, |
| 560 | { |
| 561 | /// Serialize the given data structure as a pretty-color-printed String of JSON. |
| 562 | /// |
| 563 | /// # Errors |
| 564 | /// |
| 565 | /// Serialization can fail if `T`'s implementation of `Serialize` decides to |
| 566 | /// fail, or if `T` contains a map with non-string keys. |
| 567 | fn to_colored_json_autorust-analyzer cargo colored_json 5.0.0 impl#[S][ToColoredJson]to_colored_json_auto().(&self) -> serde_jsonrust-analyzer cargo serde_json 1.0.85 crate/::Resultrust-analyzer cargo serde_json 1.0.85 error/Result#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#> { |
| 568 | let v: Valuerust-analyzer cargo serde_json 1.0.85 value/Value# = serde_jsonrust-analyzer cargo serde_json 1.0.85 crate/::from_strrust-analyzer cargo serde_json 1.0.85 de/from_str().(self.as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#as_ref().())?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 569 | to_colored_jsonrust-analyzer cargo colored_json 5.0.0 to_colored_json().(&v, ColorModerust-analyzer cargo colored_json 5.0.0 ColorMode#::Autorust-analyzer cargo colored_json 5.0.0 ColorMode#Auto#(Outputrust-analyzer cargo colored_json 5.0.0 Output#::StdOutrust-analyzer cargo colored_json 5.0.0 Output#StdOut#)) |
| 570 | } |
| 571 | |
| 572 | /// Serialize the given data structure as a pretty-color-printed String of JSON. |
| 573 | /// |
| 574 | /// # Errors |
| 575 | /// |
| 576 | /// Serialization can fail if `T`'s implementation of `Serialize` decides to |
| 577 | /// fail, or if `T` contains a map with non-string keys. |
| 578 | fn to_colored_jsonrust-analyzer cargo colored_json 5.0.0 impl#[S][ToColoredJson]to_colored_json().(&self, mode: ColorModerust-analyzer cargo colored_json 5.0.0 ColorMode#) -> serde_jsonrust-analyzer cargo serde_json 1.0.85 crate/::Resultrust-analyzer cargo serde_json 1.0.85 error/Result#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#> { |
| 579 | let v: Valuerust-analyzer cargo serde_json 1.0.85 value/Value# = serde_jsonrust-analyzer cargo serde_json 1.0.85 crate/::from_strrust-analyzer cargo serde_json 1.0.85 de/from_str().(self.as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#as_ref().())?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 580 | to_colored_jsonrust-analyzer cargo colored_json 5.0.0 to_colored_json().(&v, mode) |
| 581 | } |
| 582 | |
| 583 | /// Serialize the given data structure as a pretty-color-printed String of JSON. |
| 584 | /// |
| 585 | /// # Errors |
| 586 | /// |
| 587 | /// Serialization can fail if `T`'s implementation of `Serialize` decides to |
| 588 | /// fail, or if `T` contains a map with non-string keys. |
| 589 | fn to_colored_json_with_stylerrust-analyzer cargo colored_json 5.0.0 impl#[S][ToColoredJson]to_colored_json_with_styler().( |
| 590 | &self, |
| 591 | mode: ColorModerust-analyzer cargo colored_json 5.0.0 ColorMode#, |
| 592 | styler: Stylerrust-analyzer cargo colored_json 5.0.0 Styler#, |
| 593 | ) -> serde_jsonrust-analyzer cargo serde_json 1.0.85 crate/::Resultrust-analyzer cargo serde_json 1.0.85 error/Result#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#> { |
| 594 | let f = ColoredFormatterrust-analyzer cargo colored_json 5.0.0 ColoredFormatter#::with_stylerrust-analyzer cargo colored_json 5.0.0 impl#[`ColoredFormatter<F>`]with_styler().(PrettyFormatterrust-analyzer cargo serde_json 1.0.85 ser/PrettyFormatter#::newrust-analyzer cargo serde_json 1.0.85 ser/impl#[`PrettyFormatter<'a>`]new().(), styler); |
| 595 | let v: Valuerust-analyzer cargo serde_json 1.0.85 value/Value# = serde_jsonrust-analyzer cargo serde_json 1.0.85 crate/::from_strrust-analyzer cargo serde_json 1.0.85 de/from_str().(self.as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#as_ref().())?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 596 | f.to_colored_jsonrust-analyzer cargo colored_json 5.0.0 impl#[`ColoredFormatter<F>`]to_colored_json().(&v, mode) |
| 597 | } |
| 598 | |
| 599 | /// Serialize the given data structure as pretty-color-printed JSON into the IO |
| 600 | /// stream. |
| 601 | /// |
| 602 | /// # Errors |
| 603 | /// |
| 604 | /// Serialization can fail if `T`'s implementation of `Serialize` decides to |
| 605 | /// fail, or if `T` contains a map with non-string keys. |
| 606 | fn write_colored_jsonrust-analyzer cargo colored_json 5.0.0 impl#[S][ToColoredJson]write_colored_json().<W>(&self, writer: &mut W) -> serde_jsonrust-analyzer cargo serde_json 1.0.85 crate/::Resultrust-analyzer cargo serde_json 1.0.85 error/Result#<()> |
| 607 | where |
| 608 | W: 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#, |
| 609 | { |
| 610 | let value: Valuerust-analyzer cargo serde_json 1.0.85 value/Value# = serde_jsonrust-analyzer cargo serde_json 1.0.85 crate/::from_strrust-analyzer cargo serde_json 1.0.85 de/from_str().(self.as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#as_ref().())?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 611 | write_colored_json_with_moderust-analyzer cargo colored_json 5.0.0 write_colored_json_with_mode().(&value, writer, ColorModerust-analyzer cargo colored_json 5.0.0 ColorMode#::Autorust-analyzer cargo colored_json 5.0.0 ColorMode#Auto#(Outputrust-analyzer cargo colored_json 5.0.0 Output#::StdOutrust-analyzer cargo colored_json 5.0.0 Output#StdOut#)) |
| 612 | } |
| 613 | |
| 614 | fn write_colored_json_with_moderust-analyzer cargo colored_json 5.0.0 impl#[S][ToColoredJson]write_colored_json_with_mode().<W>( |
| 615 | &self, |
| 616 | writer: &mut W, |
| 617 | mode: ColorModerust-analyzer cargo colored_json 5.0.0 ColorMode#, |
| 618 | ) -> serde_jsonrust-analyzer cargo serde_json 1.0.85 crate/::Resultrust-analyzer cargo serde_json 1.0.85 error/Result#<()> |
| 619 | where |
| 620 | W: 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#, |
| 621 | { |
| 622 | let value: Valuerust-analyzer cargo serde_json 1.0.85 value/Value# = serde_jsonrust-analyzer cargo serde_json 1.0.85 crate/::from_strrust-analyzer cargo serde_json 1.0.85 de/from_str().(self.as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#as_ref().())?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 623 | write_colored_json_with_moderust-analyzer cargo colored_json 5.0.0 write_colored_json_with_mode().(&value, writer, mode) |
| 624 | } |
| 625 | |
| 626 | fn write_colored_json_with_stylerrust-analyzer cargo colored_json 5.0.0 impl#[S][ToColoredJson]write_colored_json_with_styler().<W>( |
| 627 | &self, |
| 628 | writer: &mut W, |
| 629 | mode: ColorModerust-analyzer cargo colored_json 5.0.0 ColorMode#, |
| 630 | styler: Stylerrust-analyzer cargo colored_json 5.0.0 Styler#, |
| 631 | ) -> serde_jsonrust-analyzer cargo serde_json 1.0.85 crate/::Resultrust-analyzer cargo serde_json 1.0.85 error/Result#<()> |
| 632 | where |
| 633 | W: 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#, |
| 634 | { |
| 635 | let value: Valuerust-analyzer cargo serde_json 1.0.85 value/Value# = serde_jsonrust-analyzer cargo serde_json 1.0.85 crate/::from_strrust-analyzer cargo serde_json 1.0.85 de/from_str().(self.as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#as_ref().())?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 636 | let f = ColoredFormatterrust-analyzer cargo colored_json 5.0.0 ColoredFormatter#::with_stylerrust-analyzer cargo colored_json 5.0.0 impl#[`ColoredFormatter<F>`]with_styler().(PrettyFormatterrust-analyzer cargo serde_json 1.0.85 ser/PrettyFormatter#::newrust-analyzer cargo serde_json 1.0.85 ser/impl#[`PrettyFormatter<'a>`]new().(), styler); |
| 637 | f.write_colored_jsonrust-analyzer cargo colored_json 5.0.0 impl#[`ColoredFormatter<F>`]write_colored_json().(&value, writer, mode) |
| 638 | } |
| 639 | } |
| 640 | |
| 641 | /// Serialize the given data structure as a pretty-color-printed String of JSON. |
| 642 | /// |
| 643 | /// # Errors |
| 644 | /// |
| 645 | /// Serialization can fail if `T`'s implementation of `Serialize` decides to |
| 646 | /// fail, or if `T` contains a map with non-string keys. |
| 647 | pub fn to_colored_json_autorust-analyzer cargo colored_json 5.0.0 to_colored_json_auto().<T>(value: &T) -> serde_jsonrust-analyzer cargo serde_json 1.0.85 crate/::Resultrust-analyzer cargo serde_json 1.0.85 error/Result#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#> |
| 648 | where |
| 649 | T: Serializerust-analyzer cargo serde 1.0.144 ser/Serialize#, |
| 650 | { |
| 651 | to_colored_jsonrust-analyzer cargo colored_json 5.0.0 to_colored_json().(value, ColorModerust-analyzer cargo colored_json 5.0.0 ColorMode#::Autorust-analyzer cargo colored_json 5.0.0 ColorMode#Auto#(Outputrust-analyzer cargo colored_json 5.0.0 Output#::StdOutrust-analyzer cargo colored_json 5.0.0 Output#StdOut#)) |
| 652 | } |
| 653 | |
| 654 | pub fn to_colored_jsonrust-analyzer cargo colored_json 5.0.0 to_colored_json().<T>(value: &T, mode: ColorModerust-analyzer cargo colored_json 5.0.0 ColorMode#) -> serde_jsonrust-analyzer cargo serde_json 1.0.85 crate/::Resultrust-analyzer cargo serde_json 1.0.85 error/Result#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#> |
| 655 | where |
| 656 | T: Serializerust-analyzer cargo serde 1.0.144 ser/Serialize#, |
| 657 | { |
| 658 | let mut writer: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8> = Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::with_capacityrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]with_capacity().(128); |
| 659 | |
| 660 | write_colored_json_with_moderust-analyzer cargo colored_json 5.0.0 write_colored_json_with_mode().(value, &mut writer, mode)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 661 | |
| 662 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::from_utf8_lossyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]from_utf8_lossy().(&writer).to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()) |
| 663 | } |
| 664 | |
| 665 | /// Serialize the given data structure as pretty-color-printed JSON into the IO |
| 666 | /// stream. |
| 667 | /// |
| 668 | /// # Errors |
| 669 | /// |
| 670 | /// Serialization can fail if `T`'s implementation of `Serialize` decides to |
| 671 | /// fail, or if `T` contains a map with non-string keys. |
| 672 | pub fn write_colored_jsonrust-analyzer cargo colored_json 5.0.0 write_colored_json().<W, T>(value: &T, writer: &mut W) -> serde_jsonrust-analyzer cargo serde_json 1.0.85 crate/::Resultrust-analyzer cargo serde_json 1.0.85 error/Result#<()> |
| 673 | where |
| 674 | W: 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#, |
| 675 | T: Serializerust-analyzer cargo serde 1.0.144 ser/Serialize#, |
| 676 | { |
| 677 | write_colored_json_with_moderust-analyzer cargo colored_json 5.0.0 write_colored_json_with_mode().(value, writer, ColorModerust-analyzer cargo colored_json 5.0.0 ColorMode#::Autorust-analyzer cargo colored_json 5.0.0 ColorMode#Auto#(Outputrust-analyzer cargo colored_json 5.0.0 Output#::StdOutrust-analyzer cargo colored_json 5.0.0 Output#StdOut#)) |
| 678 | } |
| 679 | |
| 680 | pub fn write_colored_json_with_moderust-analyzer cargo colored_json 5.0.0 write_colored_json_with_mode().<W, T>( |
| 681 | value: &T, |
| 682 | writer: &mut W, |
| 683 | mode: ColorModerust-analyzer cargo colored_json 5.0.0 ColorMode#, |
| 684 | ) -> serde_jsonrust-analyzer cargo serde_json 1.0.85 crate/::Resultrust-analyzer cargo serde_json 1.0.85 error/Result#<()> |
| 685 | where |
| 686 | W: 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#, |
| 687 | T: Serializerust-analyzer cargo serde 1.0.144 ser/Serialize#, |
| 688 | { |
| 689 | if mode.use_colorrust-analyzer cargo colored_json 5.0.0 impl#[ColorMode]use_color().() { |
| 690 | let formatter = ColoredFormatterrust-analyzer cargo colored_json 5.0.0 ColoredFormatter#::newrust-analyzer cargo colored_json 5.0.0 impl#[`ColoredFormatter<F>`]new().(PrettyFormatterrust-analyzer cargo serde_json 1.0.85 ser/PrettyFormatter#::newrust-analyzer cargo serde_json 1.0.85 ser/impl#[`PrettyFormatter<'a>`]new().()); |
| 691 | let mut serializer = serde_jsonrust-analyzer cargo serde_json 1.0.85 crate/::Serializerrust-analyzer cargo serde_json 1.0.85 ser/Serializer#::with_formatterrust-analyzer cargo serde_json 1.0.85 ser/impl#[`Serializer<W, F>`]with_formatter().(writer, formatter); |
| 692 | value.serializerust-analyzer cargo serde 1.0.144 ser/Serialize#serialize().(&mut serializer) |
| 693 | } else { |
| 694 | let formatter = PrettyFormatterrust-analyzer cargo serde_json 1.0.85 ser/PrettyFormatter#::newrust-analyzer cargo serde_json 1.0.85 ser/impl#[`PrettyFormatter<'a>`]new().(); |
| 695 | let mut serializer = serde_jsonrust-analyzer cargo serde_json 1.0.85 crate/::Serializerrust-analyzer cargo serde_json 1.0.85 ser/Serializer#::with_formatterrust-analyzer cargo serde_json 1.0.85 ser/impl#[`Serializer<W, F>`]with_formatter().(writer, formatter); |
| 696 | value.serializerust-analyzer cargo serde 1.0.144 ser/Serialize#serialize().(&mut serializer) |
| 697 | } |
| 698 | } |
| 699 | |
| 700 | /// ColorMode is a switch to enforce color mode, turn it off or auto-detect, if it should be used |
| 701 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:)] |
| 702 | pub enum ColorModerust-analyzer cargo colored_json 5.0.0 ColorMode# { |
| 703 | Onrust-analyzer cargo colored_json 5.0.0 ColorMode#On#, |
| 704 | Offrust-analyzer cargo colored_json 5.0.0 ColorMode#Off#, |
| 705 | Autorust-analyzer cargo colored_json 5.0.0 ColorMode#Auto#(Outputrust-analyzer cargo colored_json 5.0.0 Output#), |
| 706 | } |
| 707 | |
| 708 | /// Specify the output sink, which should be used for the auto detection |
| 709 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:)] |
| 710 | pub enum Outputrust-analyzer cargo colored_json 5.0.0 Output# { |
| 711 | StdOutrust-analyzer cargo colored_json 5.0.0 Output#StdOut#, |
| 712 | StdErrrust-analyzer cargo colored_json 5.0.0 Output#StdErr#, |
| 713 | } |
| 714 | |
| 715 | /// With `ColorMode` you can implement command line options like `--color=auto|on|off` easily. |
| 716 | /// |
| 717 | /// # Example: |
| 718 | /// |
| 719 | /// ```rust |
| 720 | /// # use colored_json::{ColorMode, Output}; |
| 721 | /// |
| 722 | /// let option = "--color=auto"; |
| 723 | /// |
| 724 | /// let color_mode = match option { |
| 725 | /// "--color=on" => ColorMode::Off, |
| 726 | /// "--color=off" => ColorMode::On, |
| 727 | /// _ => ColorMode::default().eval(), |
| 728 | /// }; |
| 729 | /// |
| 730 | /// assert!(match color_mode { |
| 731 | /// ColorMode::On | ColorMode::Off => true, |
| 732 | /// _ => false |
| 733 | /// }); |
| 734 | /// ``` |
| 735 | impl ColorModerust-analyzer cargo colored_json 5.0.0 ColorMode# { |
| 736 | fn is_ttyrust-analyzer cargo colored_json 5.0.0 impl#[ColorMode]is_tty().(output: Outputrust-analyzer cargo colored_json 5.0.0 Output#) -> bool { |
| 737 | match output { |
| 738 | Outputrust-analyzer cargo colored_json 5.0.0 Output#::StdOutrust-analyzer cargo colored_json 5.0.0 Output#StdOut# => iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::stdoutrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/stdio/stdout().().is_terminalrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/stdio/impl#[Stdout][IsTerminal]is_terminal().(), |
| 739 | Outputrust-analyzer cargo colored_json 5.0.0 Output#::StdErrrust-analyzer cargo colored_json 5.0.0 Output#StdErr# => iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::stderrrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/stdio/stderr().().is_terminalrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/stdio/impl#[Stderr][IsTerminal]is_terminal().(), |
| 740 | } |
| 741 | } |
| 742 | |
| 743 | /// indicates, if the `output` is capable of displaying colors and if `NO_COLOR` is not active. |
| 744 | pub fn should_colorizerust-analyzer cargo colored_json 5.0.0 impl#[ColorMode]should_colorize().(output: Outputrust-analyzer cargo colored_json 5.0.0 Output#) -> bool { |
| 745 | // check if `NO_COLOR` is present and not empty |
| 746 | if var_osrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/var_os().("NO_COLOR") |
| 747 | .filterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]filter().(|value| !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().value.is_emptyrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/impl#[OsStr]is_empty().()) |
| 748 | .is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().() |
| 749 | { |
| 750 | // color is requested to be off |
| 751 | return false; |
| 752 | } |
| 753 | |
| 754 | Selfrust-analyzer cargo colored_json 5.0.0 impl#[ColorMode]::is_ttyrust-analyzer cargo colored_json 5.0.0 impl#[ColorMode]is_tty().(output) |
| 755 | } |
| 756 | |
| 757 | /// Returns ColorMode::On or ColorMode::Off |
| 758 | /// |
| 759 | /// # Example: |
| 760 | /// |
| 761 | /// ```rust |
| 762 | /// # use colored_json::{ColorMode, Output}; |
| 763 | /// let on_off = ColorMode::default().eval(); |
| 764 | /// |
| 765 | /// assert!(match on_off { |
| 766 | /// ColorMode::On | ColorMode::Off => true, |
| 767 | /// _ => false |
| 768 | /// }); |
| 769 | /// ``` |
| 770 | pub fn evalrust-analyzer cargo colored_json 5.0.0 impl#[ColorMode]eval().(self) -> Selfrust-analyzer cargo colored_json 5.0.0 impl#[ColorMode] { |
| 771 | if self.use_colorrust-analyzer cargo colored_json 5.0.0 impl#[ColorMode]use_color().() { |
| 772 | ColorModerust-analyzer cargo colored_json 5.0.0 ColorMode#::Onrust-analyzer cargo colored_json 5.0.0 ColorMode#On# |
| 773 | } else { |
| 774 | ColorModerust-analyzer cargo colored_json 5.0.0 ColorMode#::Offrust-analyzer cargo colored_json 5.0.0 ColorMode#Off# |
| 775 | } |
| 776 | } |
| 777 | |
| 778 | /// Indicates if color should be used |
| 779 | // |
| 780 | /// # Example: |
| 781 | // |
| 782 | /// ```rust |
| 783 | /// # use colored_json::{ColorMode, Output}; |
| 784 | // |
| 785 | /// if ColorMode::default().use_color() { |
| 786 | /// println!("We can use color! :-)"); |
| 787 | /// } else { |
| 788 | /// println!("No color for you! :-("); |
| 789 | /// } |
| 790 | // |
| 791 | /// if ColorMode::Auto(Output::StdErr).use_color() { |
| 792 | /// println!("We can use color on stderr! :-)"); |
| 793 | /// } else { |
| 794 | /// println!("No color for you on stderr! :-("); |
| 795 | /// } |
| 796 | // |
| 797 | /// assert_eq!(ColorMode::On.use_color(), true); |
| 798 | /// assert_eq!(ColorMode::Off.use_color(), false); |
| 799 | /// ``` |
| 800 | pub fn use_colorrust-analyzer cargo colored_json 5.0.0 impl#[ColorMode]use_color().(self) -> bool { |
| 801 | match self { |
| 802 | ColorModerust-analyzer cargo colored_json 5.0.0 ColorMode#::Onrust-analyzer cargo colored_json 5.0.0 ColorMode#On# => true, |
| 803 | ColorModerust-analyzer cargo colored_json 5.0.0 ColorMode#::Offrust-analyzer cargo colored_json 5.0.0 ColorMode#Off# => false, |
| 804 | ColorModerust-analyzer cargo colored_json 5.0.0 ColorMode#::Autorust-analyzer cargo colored_json 5.0.0 ColorMode#Auto#(output) => Selfrust-analyzer cargo colored_json 5.0.0 impl#[ColorMode]::should_colorizerust-analyzer cargo colored_json 5.0.0 impl#[ColorMode]should_colorize().(output), |
| 805 | } |
| 806 | } |
| 807 | } |
| 808 | |
| 809 | impl Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default# for ColorModerust-analyzer cargo colored_json 5.0.0 ColorMode# { |
| 810 | /// returns `ColorMode::Auto(Output::StdOut)` |
| 811 | fn defaultrust-analyzer cargo colored_json 5.0.0 impl#[ColorMode][Default]default().() -> Selfrust-analyzer cargo colored_json 5.0.0 impl#[ColorMode][Default] { |
| 812 | ColorModerust-analyzer cargo colored_json 5.0.0 ColorMode#::Autorust-analyzer cargo colored_json 5.0.0 ColorMode#Auto#(Outputrust-analyzer cargo colored_json 5.0.0 Output#::StdOutrust-analyzer cargo colored_json 5.0.0 Output#StdOut#) |
| 813 | } |
| 814 | } |