Debian Codegraph @

src/context.rs

raw symbols SCIP
1 use craterust-analyzer cargo anyhow 1.0.103 crate/::errorrust-analyzer cargo anyhow 1.0.103 error/::ContextErrorrust-analyzer cargo anyhow 1.0.103 error/ContextError#;
2 use craterust-analyzer cargo anyhow 1.0.103 crate/::{Contextrust-analyzer cargo anyhow 1.0.103 Context#, Errorrust-analyzer cargo anyhow 1.0.103 Error#, StdErrorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core error/Error#};
3 use corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::convertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/::Infalliblerust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Infallible#;
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#, Displayrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Display#, Writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Write#};
5
6 #[cfg(error_generic_member_access)]
7 use craterust-analyzer cargo anyhow 1.0.103 crate/::nightly::{self, Request};
8
9 mod extrust-analyzer cargo anyhow 1.0.103 context/ext/ {
10 use superrust-analyzer cargo anyhow 1.0.103 context/::*;
11
12 pub trait StdErrorrust-analyzer cargo anyhow 1.0.103 context/ext/StdError# {
13 fn ext_contextrust-analyzer cargo anyhow 1.0.103 context/ext/StdError#ext_context().<C>(self, context: C) -> Errorrust-analyzer cargo anyhow 1.0.103 Error#
14 where
15 C: Displayrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Display# + Sendrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Send# + Syncrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sync# + 'static;
16 }
17
18 #[cfg(any(feature = "std", not(anyhow_no_core_error)))]
19 impl<E> StdErrorrust-analyzer cargo anyhow 1.0.103 context/ext/StdError# for E
20 where
21 E: craterust-analyzer cargo anyhow 1.0.103 crate/::StdErrorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core error/Error# + Sendrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Send# + Syncrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sync# + 'static,
22 {
23 fn ext_contextrust-analyzer cargo anyhow 1.0.103 context/ext/impl#[E][StdError]ext_context().<C>(self, context: C) -> Errorrust-analyzer cargo anyhow 1.0.103 Error#
24 where
25 C: Displayrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Display# + Sendrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Send# + Syncrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sync# + 'static,
26 {
27 let backtrace = backtrace_if_absentrust-analyzer cargo anyhow 1.0.103 backtrace/backtrace_if_absent!!(&self);
28 Errorrust-analyzer cargo anyhow 1.0.103 Error#::construct_from_contextrust-analyzer cargo anyhow 1.0.103 error/impl#[Error]construct_from_context().(context, self, backtrace)
29 }
30 }
31
32 impl StdErrorrust-analyzer cargo anyhow 1.0.103 context/ext/StdError# for Errorrust-analyzer cargo anyhow 1.0.103 Error# {
33 fn ext_contextrust-analyzer cargo anyhow 1.0.103 context/ext/impl#[Error][StdError]ext_context().<C>(self, context: C) -> Errorrust-analyzer cargo anyhow 1.0.103 Error#
34 where
35 C: Displayrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Display# + Sendrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Send# + Syncrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sync# + 'static,
36 {
37 self.contextrust-analyzer cargo anyhow 1.0.103 error/impl#[Error]context().(context)
38 }
39 }
40 }
41
42 impl<T, E> Contextrust-analyzer cargo anyhow 1.0.103 Context#<T, E> for Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<T, E>
43 where
44 E: extrust-analyzer cargo anyhow 1.0.103 context/ext/::StdErrorrust-analyzer cargo anyhow 1.0.103 context/ext/StdError# + Sendrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Send# + Syncrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sync# + 'static,
45 {
46 fn contextrust-analyzer cargo anyhow 1.0.103 context/impl#[`Result<T, E>`][`Context<T, E>`]context().<C>(self, context: C) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<T, Errorrust-analyzer cargo anyhow 1.0.103 Error#>
47 where
48 C: Displayrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Display# + Sendrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Send# + Syncrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sync# + 'static,
49 {
50 // Not using map_err to save 2 useless frames off the captured backtrace
51 // in ext_context.
52 match self {
53 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(ok) => Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(ok),
54 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(error) => Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(error.ext_contextrust-analyzer cargo anyhow 1.0.103 context/ext/StdError#ext_context().(context)),
55 }
56 }
57
58 fn with_contextrust-analyzer cargo anyhow 1.0.103 context/impl#[`Result<T, E>`][`Context<T, E>`]with_context().<C, F>(self, context: F) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<T, Errorrust-analyzer cargo anyhow 1.0.103 Error#>
59 where
60 C: Displayrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Display# + Sendrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Send# + Syncrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sync# + 'static,
61 F: FnOncerust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnOnce#() -> C,
62 {
63 match self {
64 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(ok) => Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(ok),
65 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(error) => Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(error.ext_contextrust-analyzer cargo anyhow 1.0.103 context/ext/StdError#ext_context().(context())),
66 }
67 }
68 }
69
70 /// ```
71 /// # type T = ();
72 /// #
73 /// use anyhow::{Context, Result};
74 ///
75 /// fn maybe_get() -> Option<T> {
76 /// # const IGNORE: &str = stringify! {
77 /// ...
78 /// # };
79 /// # unimplemented!()
80 /// }
81 ///
82 /// fn demo() -> Result<()> {
83 /// let t = maybe_get().context("there is no T")?;
84 /// # const IGNORE: &str = stringify! {
85 /// ...
86 /// # };
87 /// # unimplemented!()
88 /// }
89 /// ```
90 impl<T> Contextrust-analyzer cargo anyhow 1.0.103 Context#<T, Infalliblerust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Infallible#> for Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<T> {
91 fn contextrust-analyzer cargo anyhow 1.0.103 context/impl#[`Option<T>`][`Context<T, Infallible>`]context().<C>(self, context: C) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<T, Errorrust-analyzer cargo anyhow 1.0.103 Error#>
92 where
93 C: Displayrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Display# + Sendrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Send# + Syncrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sync# + 'static,
94 {
95 // Not using ok_or_else to save 2 useless frames off the captured
96 // backtrace.
97 match self {
98 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(ok) => Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(ok),
99 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#(Errorrust-analyzer cargo anyhow 1.0.103 Error#::construct_from_displayrust-analyzer cargo anyhow 1.0.103 error/impl#[Error]construct_from_display().(context, backtracerust-analyzer cargo anyhow 1.0.103 backtrace/backtrace!!())),
100 }
101 }
102
103 fn with_contextrust-analyzer cargo anyhow 1.0.103 context/impl#[`Option<T>`][`Context<T, Infallible>`]with_context().<C, F>(self, context: F) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<T, Errorrust-analyzer cargo anyhow 1.0.103 Error#>
104 where
105 C: Displayrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Display# + Sendrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Send# + Syncrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sync# + 'static,
106 F: FnOncerust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnOnce#() -> C,
107 {
108 match self {
109 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(ok) => Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(ok),
110 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#(Errorrust-analyzer cargo anyhow 1.0.103 Error#::construct_from_displayrust-analyzer cargo anyhow 1.0.103 error/impl#[Error]construct_from_display().(context(), backtracerust-analyzer cargo anyhow 1.0.103 backtrace/backtrace!!())),
111 }
112 }
113 }
114
115 impl<C, E> Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Debug# for ContextErrorrust-analyzer cargo anyhow 1.0.103 error/ContextError#<C, E>
116 where
117 C: Displayrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Display#,
118 E: Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Debug#,
119 {
120 fn fmtrust-analyzer cargo anyhow 1.0.103 context/impl#[`ContextError<C, E>`][Debug]fmt().(&self, 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# {
121 f.debug_structrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/impl#[`Formatter<'a>`]debug_struct().("Error")
122 .fieldrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/builders/impl#[`DebugStruct<'a, 'b>`]field().("context", &Quotedrust-analyzer cargo anyhow 1.0.103 context/Quoted#(&self.contextrust-analyzer cargo anyhow 1.0.103 error/ContextError#context.))
123 .fieldrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/builders/impl#[`DebugStruct<'a, 'b>`]field().("source", &self.errorrust-analyzer cargo anyhow 1.0.103 error/ContextError#error.)
124 .finishrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/builders/impl#[`DebugStruct<'a, 'b>`]finish().()
125 }
126 }
127
128 impl<C, E> Displayrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Display# for ContextErrorrust-analyzer cargo anyhow 1.0.103 error/ContextError#<C, E>
129 where
130 C: Displayrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Display#,
131 {
132 fn fmtrust-analyzer cargo anyhow 1.0.103 context/impl#[`ContextError<C, E>`][Display]fmt().(&self, 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# {
133 Displayrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Display#::fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Display#fmt().(&self.contextrust-analyzer cargo anyhow 1.0.103 error/ContextError#context., f)
134 }
135 }
136
137 impl<C, E> StdErrorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core error/Error# for ContextErrorrust-analyzer cargo anyhow 1.0.103 error/ContextError#<C, E>
138 where
139 C: Displayrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Display#,
140 E: StdErrorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core error/Error# + 'static,
141 {
142 fn sourcerust-analyzer cargo anyhow 1.0.103 context/impl#[`ContextError<C, E>`][Error]source().(&self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&(dyn StdErrorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core error/Error# + 'static)> {
143 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(&self.errorrust-analyzer cargo anyhow 1.0.103 error/ContextError#error.)
144 }
145
146 #[cfg(error_generic_member_access)]
147 fn provide<'a>(&'a self, request: &mut Request<'a>) {
148 nightly::provide(&selfrust-analyzer cargo anyhow 1.0.103 context/.error, request);
149 }
150 }
151
152 impl<C> StdErrorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core error/Error# for ContextErrorrust-analyzer cargo anyhow 1.0.103 error/ContextError#<C, Errorrust-analyzer cargo anyhow 1.0.103 Error#>
153 where
154 C: Displayrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Display#,
155 {
156 fn sourcerust-analyzer cargo anyhow 1.0.103 context/impl#[`ContextError<C, Error>`][Error]source().(&self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&(dyn StdErrorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core error/Error# + 'static)> {
157 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(unsafe { craterust-analyzer cargo anyhow 1.0.103 crate/::ErrorImplrust-analyzer cargo anyhow 1.0.103 error/ErrorImpl#::errorrust-analyzer cargo anyhow 1.0.103 error/impl#[ErrorImpl]error().(self.errorrust-analyzer cargo anyhow 1.0.103 error/ContextError#error..innerrust-analyzer cargo anyhow 1.0.103 Error#inner..by_refrust-analyzer cargo anyhow 1.0.103 ptr/impl#[`Own<T>`]by_ref().()) })
158 }
159
160 #[cfg(error_generic_member_access)]
161 fn provide<'a>(&'a self, request: &mut Request<'a>) {
162 Errorrust-analyzer cargo anyhow 1.0.103 Error#::provide(&selfrust-analyzer cargo anyhow 1.0.103 context/.error, request);
163 }
164 }
165
166 struct Quotedrust-analyzer cargo anyhow 1.0.103 context/Quoted#<C>(C);
167
168 impl<C> Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Debug# for Quotedrust-analyzer cargo anyhow 1.0.103 context/Quoted#<C>
169 where
170 C: Displayrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Display#,
171 {
172 fn fmtrust-analyzer cargo anyhow 1.0.103 context/impl#[`Quoted<C>`][Debug]fmt().(&self, formatter: &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# {
173 formatter.write_charrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/impl#[`Formatter<'_>`][Write]write_char().('"')?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
174 Quotedrust-analyzer cargo anyhow 1.0.103 context/Quoted#(&mut *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().formatter).write_fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Write#write_fmt().(format_argsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/format_args!!("{}", self.0rust-analyzer cargo anyhow 1.0.103 context/Quoted#0.))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
175 formatter.write_charrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/impl#[`Formatter<'_>`][Write]write_char().('"')?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
176 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(())
177 }
178 }
179
180 impl Writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Write# for Quotedrust-analyzer cargo anyhow 1.0.103 context/Quoted#<&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#<'_>> {
181 fn write_strrust-analyzer cargo anyhow 1.0.103 context/impl#[`Quoted<&mut fmt::Formatter<'_>>`][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# {
182 Displayrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Display#::fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/iter/impl#[`EscapeDebug<'a>`][Display]fmt().(&s.escape_debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]escape_debug().(), self.0rust-analyzer cargo anyhow 1.0.103 context/Quoted#0.)
183 }
184 }
185
186 pub(craterust-analyzer cargo anyhow 1.0.103 crate/) mod privaterust-analyzer cargo anyhow 1.0.103 context/private/ {
187 use superrust-analyzer cargo anyhow 1.0.103 context/::*;
188
189 pub trait Sealedrust-analyzer cargo anyhow 1.0.103 context/private/Sealed# {}
190
191 impl<T, E> Sealedrust-analyzer cargo anyhow 1.0.103 context/private/Sealed# for Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<T, E> where E: extrust-analyzer cargo anyhow 1.0.103 context/ext/::StdErrorrust-analyzer cargo anyhow 1.0.103 context/ext/StdError# {}
192 impl<T> Sealedrust-analyzer cargo anyhow 1.0.103 context/private/Sealed# for Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<T> {}
193 }