Skip to content

Commit fc50395

Browse files
committed
Remove the internal &mut in Requisition
Signed-off-by: Nick Cameron <[email protected]>
1 parent baaec7e commit fc50395

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

text/0000-dyno.md

+8-10
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ struct MyError {
4444
}
4545

4646
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>) {
4848
req.provide_ref::<Backtrace>(&self.backtrace)
4949
.provide_ref::<str>(&self.suggestion);
5050
}
@@ -91,11 +91,11 @@ Lets examine the changes to `Error` required to make this work:
9191
pub mod error {
9292
pub trait Error: Debug + Provider {
9393
...
94-
fn provide_context<'a>(&'a self, _req: Requisition<'a, '_>) {}
94+
fn provide_context<'a>(&'a self, _req: &mut Requisition<'a>) {}
9595
}
9696

9797
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>) {
9999
self.provide_context(req);
100100
}
101101
}
@@ -122,14 +122,14 @@ The important parts of `provide_any` are
122122
```rust
123123
pub mod provide_any {
124124
pub trait Provider {
125-
fn provide<'a>(&'a self, req: Requisition<'a, '_>);
125+
fn provide<'a>(&'a self, req: &mut Requisition<'a>);
126126
}
127127

128128
pub fn request_by_type_tag<'a, I: TypeTag<'a>>(provider: &'a dyn Provider) -> Option<I::Type> { ... }
129129

130-
pub struct Requisition<'a, 'b>(...);
130+
pub type Requisition<'a> = ...;
131131

132-
impl<'a, 'b> Requisition<'a, 'b> {
132+
impl<'a> Requisition<'a> {
133133
pub fn provide_ref<T: ?Sized + 'static>(&mut self, value: &'a T) -> &mut Self { ... }
134134
...
135135
}
@@ -211,7 +211,7 @@ For intermediate libraries, `Value` serves the common case of providing a new or
211211
### Requisition
212212

213213
```rust
214-
impl<'a, 'b> Requisition<'a, 'b> {
214+
impl<'a> Requisition<'a> {
215215
/// Provide a value or other type with only static lifetimes.
216216
pub fn provide_value<T, F>(&mut self, f: F) -> &mut Self
217217
where
@@ -244,16 +244,14 @@ impl<'a, 'b> Requisition<'a, 'b> {
244244

245245
```rust
246246
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>) {
248248
// Taking ownership of the string implies cloning it, so we use `provide_with` to avoid that
249249
// operation unless it is necessary.
250250
req.provide_with::<String>(|| self.suggestion.to_owned());
251251
}
252252
}
253253
```
254254

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-
257255

258256
# Drawbacks
259257
[drawbacks]: #drawbacks

0 commit comments

Comments
 (0)