@@ -44,7 +44,7 @@ struct MyError {
44
44
}
45
45
46
46
impl Error for MyError {
47
- fn provide_context <'a >(& 'a self , mut req : Requisition <'a , ' _ >) {
47
+ fn provide_context <'a >(& 'a self , req : & mut Requisition <'a >) {
48
48
req . provide_ref :: <Backtrace >(& self . backtrace)
49
49
. provide_ref :: <str >(& self . suggestion);
50
50
}
@@ -91,11 +91,11 @@ Lets examine the changes to `Error` required to make this work:
91
91
pub mod error {
92
92
pub trait Error : Debug + Provider {
93
93
...
94
- fn provide_context <'a >(& 'a self , _req : Requisition <'a , ' _ >) {}
94
+ fn provide_context <'a >(& 'a self , _req : & mut Requisition <'a >) {}
95
95
}
96
96
97
97
impl <T : Error > Provider for T {
98
- fn provide <'a >(& 'a self , req : Requisition <'a , ' _ >) {
98
+ fn provide <'a >(& 'a self , req : & mut Requisition <'a >) {
99
99
self . provide_context (req );
100
100
}
101
101
}
@@ -122,14 +122,14 @@ The important parts of `provide_any` are
122
122
``` rust
123
123
pub mod provide_any {
124
124
pub trait Provider {
125
- fn provide <'a >(& 'a self , req : Requisition <'a , ' _ >);
125
+ fn provide <'a >(& 'a self , req : & mut Requisition <'a >);
126
126
}
127
127
128
128
pub fn request_by_type_tag <'a , I : TypeTag <'a >>(provider : & 'a dyn Provider ) -> Option <I :: Type > { ... }
129
129
130
- pub struct Requisition <'a , ' b >( ... ) ;
130
+ pub type Requisition <'a > = ... ;
131
131
132
- impl <'a , ' b > Requisition <'a , ' b > {
132
+ impl <'a > Requisition <'a > {
133
133
pub fn provide_ref <T : ? Sized + 'static >(& mut self , value : & 'a T ) -> & mut Self { ... }
134
134
...
135
135
}
@@ -211,7 +211,7 @@ For intermediate libraries, `Value` serves the common case of providing a new or
211
211
### Requisition
212
212
213
213
``` rust
214
- impl <'a , ' b > Requisition <'a , ' b > {
214
+ impl <'a > Requisition <'a > {
215
215
/// Provide a value or other type with only static lifetimes.
216
216
pub fn provide_value <T , F >(& mut self , f : F ) -> & mut Self
217
217
where
@@ -244,16 +244,14 @@ impl<'a, 'b> Requisition<'a, 'b> {
244
244
245
245
``` rust
246
246
impl Error for MyError {
247
- fn provide_context <'a >(& 'a self , mut req : Requisition <'a , ' _ >) {
247
+ fn provide_context <'a >(& 'a self , req : & mut Requisition <'a >) {
248
248
// Taking ownership of the string implies cloning it, so we use `provide_with` to avoid that
249
249
// operation unless it is necessary.
250
250
req . provide_with :: <String >(|| self . suggestion. to_owned ());
251
251
}
252
252
}
253
253
```
254
254
255
- It seems reasonable that data might be accessed and provided on different threads. For this purpose, ` provide_any ` includes a version of ` Requisition ` which implements ` Send ` : ` SendRequisition ` . An open question is if it is also useful to support ` Sync ` variations (and if there is a better name).
256
-
257
255
258
256
# Drawbacks
259
257
[ drawbacks ] : #drawbacks
0 commit comments