Debian Codegraph @

src/fmt.rs

raw symbols SCIP
1 use craterust-analyzer cargo anyhow 1.0.103 crate/::chainrust-analyzer cargo anyhow 1.0.103 chain/::Chainrust-analyzer cargo anyhow 1.0.103 Chain#;
2 use craterust-analyzer cargo anyhow 1.0.103 crate/::errorrust-analyzer cargo anyhow 1.0.103 error/::ErrorImplrust-analyzer cargo anyhow 1.0.103 error/ErrorImpl#;
3 use craterust-analyzer cargo anyhow 1.0.103 crate/::ptrrust-analyzer cargo anyhow 1.0.103 ptr/::Refrust-analyzer cargo anyhow 1.0.103 ptr/Ref#;
4 use corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/::{selfrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Debug#, Writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Write#};
5
6 impl ErrorImplrust-analyzer cargo anyhow 1.0.103 error/ErrorImpl# {
7 pub(craterust-analyzer cargo anyhow 1.0.103 crate/) unsafe fn displayrust-analyzer cargo anyhow 1.0.103 fmt/impl#[ErrorImpl]display().(this: Refrust-analyzer cargo anyhow 1.0.103 ptr/Ref#<Selfrust-analyzer cargo anyhow 1.0.103 fmt/impl#[ErrorImpl]>, f: &mut fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/::Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#) -> fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result# {
8 writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(f, "{}", unsafe { Selfrust-analyzer cargo anyhow 1.0.103 fmt/impl#[ErrorImpl]::errorrust-analyzer cargo anyhow 1.0.103 error/impl#[ErrorImpl]error().(this) })?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
9
10 if f.alternaterust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/impl#[`Formatter<'a>`]alternate().() {
11 let chain = unsafe { Selfrust-analyzer cargo anyhow 1.0.103 fmt/impl#[ErrorImpl]::chainrust-analyzer cargo anyhow 1.0.103 error/impl#[ErrorImpl]chain().(this) };
12 for cause in chain.skiprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#skip().(1) {
13 writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(f, ": {}", cause)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
14 }
15 }
16
17 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(())
18 }
19
20 pub(craterust-analyzer cargo anyhow 1.0.103 crate/) unsafe fn debugrust-analyzer cargo anyhow 1.0.103 fmt/impl#[ErrorImpl]debug().(this: Refrust-analyzer cargo anyhow 1.0.103 ptr/Ref#<Selfrust-analyzer cargo anyhow 1.0.103 fmt/impl#[ErrorImpl]>, f: &mut fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/::Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#) -> fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result# {
21 let error = unsafe { Selfrust-analyzer cargo anyhow 1.0.103 fmt/impl#[ErrorImpl]::errorrust-analyzer cargo anyhow 1.0.103 error/impl#[ErrorImpl]error().(this) };
22
23 if f.alternaterust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/impl#[`Formatter<'a>`]alternate().() {
24 return Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Debug#::fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Debug#fmt().(error, f);
25 }
26
27 writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(f, "{}", error)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
28
29 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(cause) = error.sourcerust-analyzer cargo core https://github.com/rust-lang/rust/library/core error/Error#source().() {
30 writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(f, "\n\nCaused by:")?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
31 let multiple = cause.sourcerust-analyzer cargo core https://github.com/rust-lang/rust/library/core error/Error#source().().is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().();
32 for (n, error) in Chainrust-analyzer cargo anyhow 1.0.103 Chain#::newrust-analyzer cargo anyhow 1.0.103 chain/impl#[`Chain<'a>`]new().(cause).enumeraterust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#enumerate().() {
33 writelnrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/writeln!!(f)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
34 let mut indented = Indentedrust-analyzer cargo anyhow 1.0.103 fmt/Indented# {
35 innerrust-analyzer cargo anyhow 1.0.103 fmt/Indented#inner.: f,
36 numberrust-analyzer cargo anyhow 1.0.103 fmt/Indented#number.: if multiple { Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(n) } else { Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# },
37 startedrust-analyzer cargo anyhow 1.0.103 fmt/Indented#started.: false,
38 };
39 writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(indented, "{}", error)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
40 }
41 }
42
43 #[cfg(feature = "std")]
44 {
45 use allocrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc crate/::stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/::ToStringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/ToString#;
46 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::backtracerust-analyzer cargo std https://github.com/rust-lang/rust/library/std backtrace/::BacktraceStatusrust-analyzer cargo std https://github.com/rust-lang/rust/library/std backtrace/BacktraceStatus#;
47
48 let backtrace = unsafe { Selfrust-analyzer cargo anyhow 1.0.103 fmt/impl#[ErrorImpl]::backtracerust-analyzer cargo anyhow 1.0.103 error/impl#[ErrorImpl]backtrace().(this) };
49 if let BacktraceStatusrust-analyzer cargo std https://github.com/rust-lang/rust/library/std backtrace/BacktraceStatus#::Capturedrust-analyzer cargo std https://github.com/rust-lang/rust/library/std backtrace/BacktraceStatus#Captured# = backtrace.statusrust-analyzer cargo std https://github.com/rust-lang/rust/library/std backtrace/impl#[Backtrace]status().() {
50 let mut backtrace = backtrace.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().();
51 writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(f, "\n\n")?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
52 if backtrace.starts_withrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]starts_with().("stack backtrace:") {
53 // Capitalize to match "Caused by:"
54 backtrace.replace_rangerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]replace_range().(0..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#1, "S");
55 } else {
56 // "stack backtrace:" prefix was removed in
57 // https://github.com/rust-lang/backtrace-rs/pull/286
58 writelnrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/writeln!!(f, "Stack backtrace:")?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
59 }
60 backtrace.truncaterust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]truncate().(backtrace.trim_endrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]trim_end().().lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]len().());
61 writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(f, "{}", backtrace)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
62 }
63 }
64
65 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(())
66 }
67 }
68
69 struct Indentedrust-analyzer cargo anyhow 1.0.103 fmt/Indented#<'a, D> {
70 innerrust-analyzer cargo anyhow 1.0.103 fmt/Indented#inner.: &'a mut D,
71 numberrust-analyzer cargo anyhow 1.0.103 fmt/Indented#number.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<usize>,
72 startedrust-analyzer cargo anyhow 1.0.103 fmt/Indented#started.: bool,
73 }
74
75 impl<T> Writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Write# for Indentedrust-analyzer cargo anyhow 1.0.103 fmt/Indented#<'_, T>
76 where
77 T: Writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Write#,
78 {
79 fn write_strrust-analyzer cargo anyhow 1.0.103 fmt/impl#[`Indented<'_, T>`][Write]write_str().(&mut self, s: &str) -> fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result# {
80 for (i, line) in s.splitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]split().('\n').enumeraterust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#enumerate().() {
81 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().self.startedrust-analyzer cargo anyhow 1.0.103 fmt/Indented#started. {
82 self.startedrust-analyzer cargo anyhow 1.0.103 fmt/Indented#started. = true;
83 match self.numberrust-analyzer cargo anyhow 1.0.103 fmt/Indented#number. {
84 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(number) => writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(self.innerrust-analyzer cargo anyhow 1.0.103 fmt/Indented#inner., "{: >5}: ", number)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().,
85 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => self.innerrust-analyzer cargo anyhow 1.0.103 fmt/Indented#inner..write_strrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Write#write_str().(" ")?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().,
86 }
87 } else if i rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().0 {
88 self.innerrust-analyzer cargo anyhow 1.0.103 fmt/Indented#inner..write_charrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Write#write_char().('\n')?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
89 if self.numberrust-analyzer cargo anyhow 1.0.103 fmt/Indented#number..is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().() {
90 self.innerrust-analyzer cargo anyhow 1.0.103 fmt/Indented#inner..write_strrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Write#write_str().(" ")?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
91 } else {
92 self.innerrust-analyzer cargo anyhow 1.0.103 fmt/Indented#inner..write_strrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Write#write_str().(" ")?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
93 }
94 }
95
96 self.innerrust-analyzer cargo anyhow 1.0.103 fmt/Indented#inner..write_strrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Write#write_str().(line)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
97 }
98
99 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(())
100 }
101 }
102
103 #[cfg(test)]
104 mod testsrust-analyzer cargo anyhow 1.0.103 fmt/tests/ {
105 use superrust-analyzer cargo anyhow 1.0.103 fmt/::*;
106 use allocrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc crate/::stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/::Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#;
107
108 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
109 fn one_digitrust-analyzer cargo anyhow 1.0.103 fmt/tests/one_digit().() {
110 let input = "verify\nthis";
111 let expected = " 2: verify\n this";
112 let mut output = Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]new().();
113
114 Indentedrust-analyzer cargo anyhow 1.0.103 fmt/Indented# {
115 innerrust-analyzer cargo anyhow 1.0.103 fmt/Indented#inner.: &mut output,
116 numberrust-analyzer cargo anyhow 1.0.103 fmt/Indented#number.: Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(2),
117 startedrust-analyzer cargo anyhow 1.0.103 fmt/Indented#started.: false,
118 }
119 .write_strrust-analyzer cargo anyhow 1.0.103 fmt/impl#[`Indented<'_, T>`][Write]write_str().(input)
120 .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
121
122 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(expected, output);
123 }
124
125 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
126 fn two_digitsrust-analyzer cargo anyhow 1.0.103 fmt/tests/two_digits().() {
127 let input = "verify\nthis";
128 let expected = " 12: verify\n this";
129 let mut output = Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]new().();
130
131 Indentedrust-analyzer cargo anyhow 1.0.103 fmt/Indented# {
132 innerrust-analyzer cargo anyhow 1.0.103 fmt/Indented#inner.: &mut output,
133 numberrust-analyzer cargo anyhow 1.0.103 fmt/Indented#number.: Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(12),
134 startedrust-analyzer cargo anyhow 1.0.103 fmt/Indented#started.: false,
135 }
136 .write_strrust-analyzer cargo anyhow 1.0.103 fmt/impl#[`Indented<'_, T>`][Write]write_str().(input)
137 .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
138
139 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(expected, output);
140 }
141
142 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
143 fn no_digitsrust-analyzer cargo anyhow 1.0.103 fmt/tests/no_digits().() {
144 let input = "verify\nthis";
145 let expected = " verify\n this";
146 let mut output = Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]new().();
147
148 Indentedrust-analyzer cargo anyhow 1.0.103 fmt/Indented# {
149 innerrust-analyzer cargo anyhow 1.0.103 fmt/Indented#inner.: &mut output,
150 numberrust-analyzer cargo anyhow 1.0.103 fmt/Indented#number.: Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#,
151 startedrust-analyzer cargo anyhow 1.0.103 fmt/Indented#started.: false,
152 }
153 .write_strrust-analyzer cargo anyhow 1.0.103 fmt/impl#[`Indented<'_, T>`][Write]write_str().(input)
154 .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
155
156 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(expected, output);
157 }
158 }