Debian Codegraph @

examples/readme_preview.rs

raw symbols SCIP
1 //! Renders the preview SVG for the README.
2 //!
3 //! To update the preview, execute the following command from the top level of
4 //! the repository:
5 //!
6 //! ```sh
7 //! cargo run --example readme_preview svg > codespan-reporting/assets/readme_preview.svg
8 //! ```
9
10 use codespan_reportingrust-analyzer cargo codespan-reporting 0.12.0 crate/::diagnosticrust-analyzer cargo codespan-reporting 0.12.0 diagnostic/::{Diagnosticrust-analyzer cargo codespan-reporting 0.12.0 diagnostic/Diagnostic#, Labelrust-analyzer cargo codespan-reporting 0.12.0 diagnostic/Label#};
11 use codespan_reportingrust-analyzer cargo codespan-reporting 0.12.0 crate/::filesrust-analyzer cargo codespan-reporting 0.12.0 files/::SimpleFilerust-analyzer cargo codespan-reporting 0.12.0 files/SimpleFile#;
12 use codespan_reportingrust-analyzer cargo codespan-reporting 0.12.0 crate/::termrust-analyzer cargo codespan-reporting 0.12.0 term/::termcolorrust-analyzer cargo termcolor 1.4.1 crate/::{
13 Colorrust-analyzer cargo termcolor 1.4.1 Color#, ColorChoicerust-analyzer cargo termcolor 1.4.1 ColorChoice#, ColorSpecrust-analyzer cargo termcolor 1.4.1 ColorSpec#, StandardStreamrust-analyzer cargo termcolor 1.4.1 StandardStream#, WriteColorrust-analyzer cargo termcolor 1.4.1 WriteColor#,
14 };
15 use codespan_reportingrust-analyzer cargo codespan-reporting 0.12.0 crate/::termrust-analyzer cargo codespan-reporting 0.12.0 term/::{selfrust-analyzer cargo codespan-reporting 0.12.0 term/};
16 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/, Writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#};
17
18 #[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:)]
19 pub enum Optsrust-analyzer cargo codespan-reporting 0.12.0 Opts# {
20 /// Render SVG output
21 Svgrust-analyzer cargo codespan-reporting 0.12.0 Opts#Svg#,
22 /// Render Stderr output
23 Stderrrust-analyzer cargo codespan-reporting 0.12.0 Opts#Stderr# {
24 /// Configure coloring of output
25 colorrust-analyzer cargo codespan-reporting 0.12.0 Opts#Stderr#color.: ColorChoicerust-analyzer cargo termcolor 1.4.1 ColorChoice#,
26 },
27 }
28
29 fn parse_argsrust-analyzer cargo codespan-reporting 0.12.0 parse_args().() -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Optsrust-analyzer cargo codespan-reporting 0.12.0 Opts#, pico_argsrust-analyzer cargo pico-args 0.5.0 crate/::Errorrust-analyzer cargo pico-args 0.5.0 Error#> {
30 let mut pargs = pico_argsrust-analyzer cargo pico-args 0.5.0 crate/::Argumentsrust-analyzer cargo pico-args 0.5.0 Arguments#::from_envrust-analyzer cargo pico-args 0.5.0 impl#[Arguments]from_env().();
31 match pargs.subcommandrust-analyzer cargo pico-args 0.5.0 impl#[Arguments]subcommand().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch(). {
32 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(value) => match value.as_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]as_str().() {
33 "svg" => Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Optsrust-analyzer cargo codespan-reporting 0.12.0 Opts#::Svgrust-analyzer cargo codespan-reporting 0.12.0 Opts#Svg#),
34 "stderr" => {
35 let color = pargs
36 .opt_value_from_strrust-analyzer cargo pico-args 0.5.0 impl#[Arguments]opt_value_from_str().("--color")?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().
37 .unwrap_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or().(ColorChoicerust-analyzer cargo termcolor 1.4.1 ColorChoice#::Autorust-analyzer cargo termcolor 1.4.1 ColorChoice#Auto#);
38 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Optsrust-analyzer cargo codespan-reporting 0.12.0 Opts#::Stderrrust-analyzer cargo codespan-reporting 0.12.0 Opts#Stderr# { colorrust-analyzer cargo codespan-reporting 0.12.0 Opts#Stderr#color. })
39 }
40 _ => Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(pico_argsrust-analyzer cargo pico-args 0.5.0 crate/::Errorrust-analyzer cargo pico-args 0.5.0 Error#::Utf8ArgumentParsingFailedrust-analyzer cargo pico-args 0.5.0 Error#Utf8ArgumentParsingFailed# {
41 valuerust-analyzer cargo pico-args 0.5.0 Error#Utf8ArgumentParsingFailed#value.,
42 causerust-analyzer cargo pico-args 0.5.0 Error#Utf8ArgumentParsingFailed#cause.: "not a valid subcommand".to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().(),
43 }),
44 },
45 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(pico_argsrust-analyzer cargo pico-args 0.5.0 crate/::Errorrust-analyzer cargo pico-args 0.5.0 Error#::MissingArgumentrust-analyzer cargo pico-args 0.5.0 Error#MissingArgument#),
46 }
47 }
48
49 fn mainrust-analyzer cargo codespan-reporting 0.12.0 main().() -> anyhowrust-analyzer cargo anyhow 1.0.0 crate/::Resultrust-analyzer cargo anyhow 1.0.0 Result#<()> {
50 let file = SimpleFilerust-analyzer cargo codespan-reporting 0.12.0 files/SimpleFile#::newrust-analyzer cargo codespan-reporting 0.12.0 files/impl#[`SimpleFile<Name, Source>`]new().(
51 "FizzBuzz.fun",
52 unindentrust-analyzer cargo unindent 0.2.4 crate/::unindentrust-analyzer cargo unindent 0.2.4 unindent/unindent().(
53 r#"
54 module FizzBuzz where
55
56 fizz₁ : Nat → String
57 fizz₁ num = case (mod num 5) (mod num 3) of
58 0 0 => "FizzBuzz"
59 0 _ => "Fizz"
60 _ 0 => "Buzz"
61 _ _ => num
62
63 fizz₂ : Nat → String
64 fizz₂ num =
65 case (mod num 5) (mod num 3) of
66 0 0 => "FizzBuzz"
67 0 _ => "Fizz"
68 _ 0 => "Buzz"
69 _ _ => num
70 "#,
71 ),
72 );
73
74 let diagnostics = [Diagnosticrust-analyzer cargo codespan-reporting 0.12.0 diagnostic/Diagnostic#::errorrust-analyzer cargo codespan-reporting 0.12.0 diagnostic/impl#[`Diagnostic<FileId>`]error().()
75 .with_messagerust-analyzer cargo codespan-reporting 0.12.0 diagnostic/impl#[`Diagnostic<FileId>`]with_message().("`case` clauses have incompatible types")
76 .with_coderust-analyzer cargo codespan-reporting 0.12.0 diagnostic/impl#[`Diagnostic<FileId>`]with_code().("E0308")
77 .with_labelsrust-analyzer cargo codespan-reporting 0.12.0 diagnostic/impl#[`Diagnostic<FileId>`]with_labels().(vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![
78 Labelrust-analyzer cargo codespan-reporting 0.12.0 diagnostic/Label#::primaryrust-analyzer cargo codespan-reporting 0.12.0 diagnostic/impl#[`Label<FileId>`]primary().((), 328..331).with_messagerust-analyzer cargo codespan-reporting 0.12.0 diagnostic/impl#[`Label<FileId>`]with_message().("expected `String`, found `Nat`"),
79 Labelrust-analyzer cargo codespan-reporting 0.12.0 diagnostic/Label#::secondaryrust-analyzer cargo codespan-reporting 0.12.0 diagnostic/impl#[`Label<FileId>`]secondary().((), 211..331).with_messagerust-analyzer cargo codespan-reporting 0.12.0 diagnostic/impl#[`Label<FileId>`]with_message().("`case` clauses have incompatible types"),
80 Labelrust-analyzer cargo codespan-reporting 0.12.0 diagnostic/Label#::secondaryrust-analyzer cargo codespan-reporting 0.12.0 diagnostic/impl#[`Label<FileId>`]secondary().((), 258..268).with_messagerust-analyzer cargo codespan-reporting 0.12.0 diagnostic/impl#[`Label<FileId>`]with_message().("this is found to be of type `String`"),
81 Labelrust-analyzer cargo codespan-reporting 0.12.0 diagnostic/Label#::secondaryrust-analyzer cargo codespan-reporting 0.12.0 diagnostic/impl#[`Label<FileId>`]secondary().((), 284..290).with_messagerust-analyzer cargo codespan-reporting 0.12.0 diagnostic/impl#[`Label<FileId>`]with_message().("this is found to be of type `String`"),
82 Labelrust-analyzer cargo codespan-reporting 0.12.0 diagnostic/Label#::secondaryrust-analyzer cargo codespan-reporting 0.12.0 diagnostic/impl#[`Label<FileId>`]secondary().((), 306..312).with_messagerust-analyzer cargo codespan-reporting 0.12.0 diagnostic/impl#[`Label<FileId>`]with_message().("this is found to be of type `String`"),
83 Labelrust-analyzer cargo codespan-reporting 0.12.0 diagnostic/Label#::secondaryrust-analyzer cargo codespan-reporting 0.12.0 diagnostic/impl#[`Label<FileId>`]secondary().((), 186..192).with_messagerust-analyzer cargo codespan-reporting 0.12.0 diagnostic/impl#[`Label<FileId>`]with_message().("expected type `String` found here"),
84 ])
85 .with_notesrust-analyzer cargo codespan-reporting 0.12.0 diagnostic/impl#[`Diagnostic<FileId>`]with_notes().(vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![unindentrust-analyzer cargo unindent 0.2.4 crate/::unindentrust-analyzer cargo unindent 0.2.4 unindent/unindent().(
86 "
87 expected type `String`
88 found type `Nat`
89 ",
90 )])];
91
92 match parse_argsrust-analyzer cargo codespan-reporting 0.12.0 parse_args().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch(). {
93 Optsrust-analyzer cargo codespan-reporting 0.12.0 Opts#::Svgrust-analyzer cargo codespan-reporting 0.12.0 Opts#Svg# => {
94 let mut buffer = Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]new().();
95 let mut writer = HtmlEscapeWriterrust-analyzer cargo codespan-reporting 0.12.0 HtmlEscapeWriter#::newrust-analyzer cargo codespan-reporting 0.12.0 impl#[`HtmlEscapeWriter<W>`]new().(SvgWriterrust-analyzer cargo codespan-reporting 0.12.0 SvgWriter#::newrust-analyzer cargo codespan-reporting 0.12.0 impl#[`SvgWriter<W>`]new().(&mut buffer));
96 let config = codespan_reportingrust-analyzer cargo codespan-reporting 0.12.0 crate/::termrust-analyzer cargo codespan-reporting 0.12.0 term/::Configrust-analyzer cargo codespan-reporting 0.12.0 term/config/Config# {
97 #[cfg(feature = "termcolor")]
98 stylesrust-analyzer cargo codespan-reporting 0.12.0 term/config/Config#styles.: codespan_reportingrust-analyzer cargo codespan-reporting 0.12.0 crate/::termrust-analyzer cargo codespan-reporting 0.12.0 term/::Stylesrust-analyzer cargo codespan-reporting 0.12.0 term/config/Styles#::with_bluerust-analyzer cargo codespan-reporting 0.12.0 term/config/impl#[Styles]with_blue().(Colorrust-analyzer cargo termcolor 1.4.1 Color#::Bluerust-analyzer cargo termcolor 1.4.1 Color#Blue#),
99 ..codespan_reportingrust-analyzer cargo codespan-reporting 0.12.0 crate/::termrust-analyzer cargo codespan-reporting 0.12.0 term/::Configrust-analyzer cargo codespan-reporting 0.12.0 term/config/Config#::defaultrust-analyzer cargo codespan-reporting 0.12.0 term/config/impl#[Config][Default]default().()
100 };
101
102 for diagnostic in &diagnostics {
103 termrust-analyzer cargo codespan-reporting 0.12.0 term/::emitrust-analyzer cargo codespan-reporting 0.12.0 term/emit().(&mut writer, &config, &file, diagnostic)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
104 }
105
106 let num_lines = buffer.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().filterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#filter().(|byte| *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().byte rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().b'\n').countrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/filter/impl#[`Filter<I, P>`][Iterator]count().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().1;
107
108 let padding = 10;
109 let font_size = 12;
110 let line_spacing = 3;
111 let width = 882;
112 let height = padding rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().num_lines rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul().(font_size rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().line_spacing) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().padding;
113
114 let stdout = 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/::stdoutrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/stdio/stdout().();
115 let writer = &mut stdout.lockrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/stdio/impl#[Stdout]lock().();
116
117 writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(
118 writer,
119 r#"<svg viewBox="0 0 {width} {height}" xmlns="http://www.w3.org/2000/svg">
120 <style>
121 /* https://github.com/aaron-williamson/base16-alacritty/blob/master/colors/base16-tomorrow-night-256.yml */
122 pre {{
123 background: #1d1f21;
124 margin: 0;
125 padding: {padding}px;
126 border-radius: 6px;
127 color: #ffffff;
128 font: {font_size}px SFMono-Regular, Consolas, Liberation Mono, Menlo, monospace;
129 }}
130
131 pre .bold {{ font-weight: bold; }}
132
133 pre .fg.black {{ color: #1d1f21; }}
134 pre .fg.red {{ color: #cc6666; }}
135 pre .fg.green {{ color: #b5bd68; }}
136 pre .fg.yellow {{ color: #f0c674; }}
137 pre .fg.blue {{ color: #81a2be; }}
138 pre .fg.magenta {{ color: #b294bb; }}
139 pre .fg.cyan {{ color: #8abeb7; }}
140 pre .fg.white {{ color: #c5c8c6; }}
141
142 pre .fg.black.bright {{ color: #969896; }}
143 pre .fg.red.bright {{ color: #cc6666; }}
144 pre .fg.green.bright {{ color: #b5bd68; }}
145 pre .fg.yellow.bright {{ color: #f0c674; }}
146 pre .fg.blue.bright {{ color: #81a2be; }}
147 pre .fg.magenta.bright {{ color: #b294bb; }}
148 pre .fg.cyan.bright {{ color: #8abeb7; }}
149 pre .fg.white.bright {{ color: #ffffff; }}
150
151 pre .bg.black {{ background-color: #1d1f21; }}
152 pre .bg.red {{ background-color: #cc6666; }}
153 pre .bg.green {{ background-color: #b5bd68; }}
154 pre .bg.yellow {{ background-color: #f0c674; }}
155 pre .bg.blue {{ background-color: #81a2be; }}
156 pre .bg.magenta {{ background-color: #b294bb; }}
157 pre .bg.cyan {{ background-color: #8abeb7; }}
158 pre .bg.white {{ background-color: #c5c8c6; }}
159
160 pre .bg.black.bright {{ background-color: #969896; }}
161 pre .bg.red.bright {{ background-color: #cc6666; }}
162 pre .bg.green.bright {{ background-color: #b5bd68; }}
163 pre .bg.yellow.bright {{ background-color: #f0c674; }}
164 pre .bg.blue.bright {{ background-color: #81a2be; }}
165 pre .bg.magenta.bright {{ background-color: #b294bb; }}
166 pre .bg.cyan.bright {{ background-color: #8abeb7; }}
167 pre .bg.white.bright {{ background-color: #ffffff; }}
168 </style>
169
170 <foreignObject x="0" y="0" width="{width}" height="{height}">
171 <div xmlns="http://www.w3.org/1999/xhtml">
172 <pre>"#,
173 padding = padding,
174 font_size = font_size,
175 width = width,
176 height = height,
177 )?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
178
179 writer.write_allrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/stdio/impl#[`StdoutLock<'_>`][Write]write_all().(&buffer)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
180
181 writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(
182 writer,
183 "</pre>
184 </div>
185 </foreignObject>
186 </svg>
187 "
188 )?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
189 }
190 Optsrust-analyzer cargo codespan-reporting 0.12.0 Opts#::Stderrrust-analyzer cargo codespan-reporting 0.12.0 Opts#Stderr# { colorrust-analyzer cargo codespan-reporting 0.12.0 Opts#Stderr#color. } => {
191 let writer = StandardStreamrust-analyzer cargo termcolor 1.4.1 StandardStream#::stderrrust-analyzer cargo termcolor 1.4.1 impl#[StandardStream]stderr().(color);
192 let config = codespan_reportingrust-analyzer cargo codespan-reporting 0.12.0 crate/::termrust-analyzer cargo codespan-reporting 0.12.0 term/::Configrust-analyzer cargo codespan-reporting 0.12.0 term/config/Config#::defaultrust-analyzer cargo codespan-reporting 0.12.0 term/config/impl#[Config][Default]default().();
193 for diagnostic in &diagnostics {
194 termrust-analyzer cargo codespan-reporting 0.12.0 term/::emitrust-analyzer cargo codespan-reporting 0.12.0 term/emit().(&mut writer.lockrust-analyzer cargo termcolor 1.4.1 impl#[StandardStream]lock().(), &config, &file, diagnostic)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
195 }
196 }
197 }
198
199 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(())
200 }
201
202 /// Rudimentary HTML escaper which performs the following conversions:
203 ///
204 /// - `<` ⇒ `&lt;`
205 /// - `>` ⇒ `&gt;`
206 /// - `&` ⇒ `&amp;`
207 pub struct HtmlEscapeWriterrust-analyzer cargo codespan-reporting 0.12.0 HtmlEscapeWriter#<W> {
208 upstreamrust-analyzer cargo codespan-reporting 0.12.0 HtmlEscapeWriter#upstream.: W,
209 }
210
211 impl<W> HtmlEscapeWriterrust-analyzer cargo codespan-reporting 0.12.0 HtmlEscapeWriter#<W> {
212 pub fn newrust-analyzer cargo codespan-reporting 0.12.0 impl#[`HtmlEscapeWriter<W>`]new().(upstream: W) -> HtmlEscapeWriterrust-analyzer cargo codespan-reporting 0.12.0 HtmlEscapeWriter#<W> {
213 HtmlEscapeWriterrust-analyzer cargo codespan-reporting 0.12.0 HtmlEscapeWriter# { upstreamrust-analyzer cargo codespan-reporting 0.12.0 HtmlEscapeWriter#upstream. }
214 }
215 }
216
217 impl<W: Writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#> Writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write# for HtmlEscapeWriterrust-analyzer cargo codespan-reporting 0.12.0 HtmlEscapeWriter#<W> {
218 fn writerust-analyzer cargo codespan-reporting 0.12.0 impl#[`HtmlEscapeWriter<W>`][Write]write().(&mut self, buf: &[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#<usize> {
219 let mut last_term = 0usize;
220 for (i, byte) in buf.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().enumeraterust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#enumerate().() {
221 let escape = match byte {
222 b'<' => &b"&lt;"[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFull#]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().,
223 b'>' => &b"&gt;"[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFull#]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().,
224 b'&' => &b"&amp;"[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFull#]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().,
225 _ => continue,
226 };
227 self.upstreamrust-analyzer cargo codespan-reporting 0.12.0 HtmlEscapeWriter#upstream..write_allrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#write_all().(&buf[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().last_term..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#i]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
228 last_term = i rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().1;
229 self.upstreamrust-analyzer cargo codespan-reporting 0.12.0 HtmlEscapeWriter#upstream..write_allrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#write_all().(escape)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
230 }
231 self.upstreamrust-analyzer cargo codespan-reporting 0.12.0 HtmlEscapeWriter#upstream..write_allrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#write_all().(&buf[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().last_term..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFrom#]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
232 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(buf.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().())
233 }
234
235 fn flushrust-analyzer cargo codespan-reporting 0.12.0 impl#[`HtmlEscapeWriter<W>`][Write]flush().(&mut self) -> 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#<()> {
236 self.upstreamrust-analyzer cargo codespan-reporting 0.12.0 HtmlEscapeWriter#upstream..flushrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#flush().()
237 }
238 }
239
240 impl<W: WriteColorrust-analyzer cargo termcolor 1.4.1 WriteColor#> WriteColorrust-analyzer cargo termcolor 1.4.1 WriteColor# for HtmlEscapeWriterrust-analyzer cargo codespan-reporting 0.12.0 HtmlEscapeWriter#<W> {
241 fn supports_colorrust-analyzer cargo codespan-reporting 0.12.0 impl#[`HtmlEscapeWriter<W>`][WriteColor]supports_color().(&self) -> bool {
242 self.upstreamrust-analyzer cargo codespan-reporting 0.12.0 HtmlEscapeWriter#upstream..supports_colorrust-analyzer cargo termcolor 1.4.1 WriteColor#supports_color().()
243 }
244
245 fn set_colorrust-analyzer cargo codespan-reporting 0.12.0 impl#[`HtmlEscapeWriter<W>`][WriteColor]set_color().(&mut self, spec: &ColorSpecrust-analyzer cargo termcolor 1.4.1 ColorSpec#) -> 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#<()> {
246 self.upstreamrust-analyzer cargo codespan-reporting 0.12.0 HtmlEscapeWriter#upstream..set_colorrust-analyzer cargo termcolor 1.4.1 WriteColor#set_color().(spec)
247 }
248
249 fn resetrust-analyzer cargo codespan-reporting 0.12.0 impl#[`HtmlEscapeWriter<W>`][WriteColor]reset().(&mut self) -> 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 self.upstreamrust-analyzer cargo codespan-reporting 0.12.0 HtmlEscapeWriter#upstream..resetrust-analyzer cargo termcolor 1.4.1 WriteColor#reset().()
251 }
252 }
253
254 pub struct SvgWriterrust-analyzer cargo codespan-reporting 0.12.0 SvgWriter#<W> {
255 upstreamrust-analyzer cargo codespan-reporting 0.12.0 SvgWriter#upstream.: W,
256 colorrust-analyzer cargo codespan-reporting 0.12.0 SvgWriter#color.: ColorSpecrust-analyzer cargo termcolor 1.4.1 ColorSpec#,
257 }
258
259 impl<W> SvgWriterrust-analyzer cargo codespan-reporting 0.12.0 SvgWriter#<W> {
260 pub fn newrust-analyzer cargo codespan-reporting 0.12.0 impl#[`SvgWriter<W>`]new().(upstream: W) -> SvgWriterrust-analyzer cargo codespan-reporting 0.12.0 SvgWriter#<W> {
261 SvgWriterrust-analyzer cargo codespan-reporting 0.12.0 SvgWriter# {
262 upstreamrust-analyzer cargo codespan-reporting 0.12.0 SvgWriter#upstream.,
263 colorrust-analyzer cargo codespan-reporting 0.12.0 SvgWriter#color.: ColorSpecrust-analyzer cargo termcolor 1.4.1 ColorSpec#::newrust-analyzer cargo termcolor 1.4.1 impl#[ColorSpec]new().(),
264 }
265 }
266 }
267
268 impl<W: Writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#> Writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write# for SvgWriterrust-analyzer cargo codespan-reporting 0.12.0 SvgWriter#<W> {
269 fn writerust-analyzer cargo codespan-reporting 0.12.0 impl#[`SvgWriter<W>`][Write]write().(&mut self, buf: &[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#<usize> {
270 self.upstreamrust-analyzer cargo codespan-reporting 0.12.0 SvgWriter#upstream..writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#write().(buf)
271 }
272
273 fn flushrust-analyzer cargo codespan-reporting 0.12.0 impl#[`SvgWriter<W>`][Write]flush().(&mut self) -> 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#<()> {
274 self.upstreamrust-analyzer cargo codespan-reporting 0.12.0 SvgWriter#upstream..flushrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#flush().()
275 }
276 }
277
278 impl<W: Writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#> WriteColorrust-analyzer cargo termcolor 1.4.1 WriteColor# for SvgWriterrust-analyzer cargo codespan-reporting 0.12.0 SvgWriter#<W> {
279 fn supports_colorrust-analyzer cargo codespan-reporting 0.12.0 impl#[`SvgWriter<W>`][WriteColor]supports_color().(&self) -> bool {
280 true
281 }
282
283 fn set_colorrust-analyzer cargo codespan-reporting 0.12.0 impl#[`SvgWriter<W>`][WriteColor]set_color().(&mut self, spec: &ColorSpecrust-analyzer cargo termcolor 1.4.1 ColorSpec#) -> 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#<()> {
284 #![allow(unused_assignments)]
285
286 if self.colorrust-analyzer cargo codespan-reporting 0.12.0 SvgWriter#color. rust-analyzer cargo termcolor 1.4.1 impl#[ColorSpec][`PartialEq<Self>`]eq().==rust-analyzer cargo termcolor 1.4.1 impl#[ColorSpec][`PartialEq<Self>`]eq(). rust-analyzer cargo termcolor 1.4.1 impl#[ColorSpec][`PartialEq<Self>`]eq().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().spec {
287 return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(());
288 } else {
289 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().self.colorrust-analyzer cargo codespan-reporting 0.12.0 SvgWriter#color..is_nonerust-analyzer cargo termcolor 1.4.1 impl#[ColorSpec]is_none().() {
290 writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(self, "</span>")?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
291 }
292 self.colorrust-analyzer cargo codespan-reporting 0.12.0 SvgWriter#color. = spec.clonerust-analyzer cargo termcolor 1.4.1 impl#[ColorSpec][Clone]clone().();
293 }
294
295 if spec.is_nonerust-analyzer cargo termcolor 1.4.1 impl#[ColorSpec]is_none().() {
296 writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(self, "</span>")?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
297 return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(());
298 } else {
299 writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(self, "<span class=\"")?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
300 }
301
302 let mut first = true;
303
304 fn write_firstrust-analyzer cargo codespan-reporting 0.12.0 write_first().<W: Writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#>(first: bool, writer: &mut SvgWriterrust-analyzer cargo codespan-reporting 0.12.0 SvgWriter#<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#<bool> {
305 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().first {
306 writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(writer, " ")?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
307 }
308
309 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(false)
310 }
311
312 fn write_colorrust-analyzer cargo codespan-reporting 0.12.0 write_color().<W: Writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#>(color: &Colorrust-analyzer cargo termcolor 1.4.1 Color#, writer: &mut SvgWriterrust-analyzer cargo codespan-reporting 0.12.0 SvgWriter#<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#<()> {
313 match color {
314 Colorrust-analyzer cargo termcolor 1.4.1 Color#::Blackrust-analyzer cargo termcolor 1.4.1 Color#Black# => writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(writer, "black"),
315 Colorrust-analyzer cargo termcolor 1.4.1 Color#::Bluerust-analyzer cargo termcolor 1.4.1 Color#Blue# => writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(writer, "blue"),
316 Colorrust-analyzer cargo termcolor 1.4.1 Color#::Greenrust-analyzer cargo termcolor 1.4.1 Color#Green# => writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(writer, "green"),
317 Colorrust-analyzer cargo termcolor 1.4.1 Color#::Redrust-analyzer cargo termcolor 1.4.1 Color#Red# => writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(writer, "red"),
318 Colorrust-analyzer cargo termcolor 1.4.1 Color#::Cyanrust-analyzer cargo termcolor 1.4.1 Color#Cyan# => writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(writer, "cyan"),
319 Colorrust-analyzer cargo termcolor 1.4.1 Color#::Magentarust-analyzer cargo termcolor 1.4.1 Color#Magenta# => writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(writer, "magenta"),
320 Colorrust-analyzer cargo termcolor 1.4.1 Color#::Yellowrust-analyzer cargo termcolor 1.4.1 Color#Yellow# => writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(writer, "yellow"),
321 Colorrust-analyzer cargo termcolor 1.4.1 Color#::Whiterust-analyzer cargo termcolor 1.4.1 Color#White# => writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(writer, "white"),
322 // TODO: other colors
323 _ => Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()),
324 }
325 }
326
327 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(fg) = spec.fgrust-analyzer cargo termcolor 1.4.1 impl#[ColorSpec]fg().() {
328 first = write_firstrust-analyzer cargo codespan-reporting 0.12.0 write_first().(first, self)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
329 writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(self, "fg ")?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
330 write_colorrust-analyzer cargo codespan-reporting 0.12.0 write_color().(fg, self)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
331 }
332
333 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(bg) = spec.bgrust-analyzer cargo termcolor 1.4.1 impl#[ColorSpec]bg().() {
334 first = write_firstrust-analyzer cargo codespan-reporting 0.12.0 write_first().(first, self)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
335 writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(self, "bg ")?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
336 write_colorrust-analyzer cargo codespan-reporting 0.12.0 write_color().(bg, self)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
337 }
338
339 if spec.boldrust-analyzer cargo termcolor 1.4.1 impl#[ColorSpec]bold().() {
340 first = write_firstrust-analyzer cargo codespan-reporting 0.12.0 write_first().(first, self)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
341 writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(self, "bold")?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
342 }
343
344 if spec.underlinerust-analyzer cargo termcolor 1.4.1 impl#[ColorSpec]underline().() {
345 first = write_firstrust-analyzer cargo codespan-reporting 0.12.0 write_first().(first, self)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
346 writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(self, "underline")?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
347 }
348
349 if spec.intenserust-analyzer cargo termcolor 1.4.1 impl#[ColorSpec]intense().() {
350 first = write_firstrust-analyzer cargo codespan-reporting 0.12.0 write_first().(first, self)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
351 writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(self, "bright")?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
352 }
353
354 writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(self, "\">")?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
355
356 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(())
357 }
358
359 fn resetrust-analyzer cargo codespan-reporting 0.12.0 impl#[`SvgWriter<W>`][WriteColor]reset().(&mut self) -> 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 let color = self.colorrust-analyzer cargo codespan-reporting 0.12.0 SvgWriter#color..clonerust-analyzer cargo termcolor 1.4.1 impl#[ColorSpec][Clone]clone().();
361
362 if color rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#ne().ColorSpecrust-analyzer cargo termcolor 1.4.1 ColorSpec#::newrust-analyzer cargo termcolor 1.4.1 impl#[ColorSpec]new().() {
363 writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(self, "</span>")?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
364 self.colorrust-analyzer cargo codespan-reporting 0.12.0 SvgWriter#color. = ColorSpecrust-analyzer cargo termcolor 1.4.1 ColorSpec#::newrust-analyzer cargo termcolor 1.4.1 impl#[ColorSpec]new().();
365 }
366
367 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(())
368 }
369 }