History

[ref] Try using BorrowMut to avoid blanket trait impls, but…

…that fails to infer the type of the delegate making calls to it rather cumbersome. Maybe that will work one day.

Sebastian Thiel committed 5 years ago

Commit 4bb9bba1 parent 0995c223 files · +21 −34Browse files

Showing the changes to git-protocol/src/fetch/function.rs (1 of 3 files). Show all

Unified · Split

git-protocol/src/fetch/function.rs+20−9
@@ -9,7 +9,7 @@ use git_transport::{ · 8 unmodified lines
99 Service,
1010 };
1111 use maybe_async::maybe_async;
12−use std::io;
12+use std::{borrow::BorrowMut, io};
1313
1414 /// Perform a 'fetch' operation with the server using `transport`, with `delegate` handling all server interactions.
1515 /// **Note** that `delegate` has blocking operations and thus this entire call should be on an executor which can handle
@@ -21,23 +21,25 @@ use std::io; · 5 unmodified lines
2121 ///
2222 /// _Note_ that depending on the `delegate`, the actual action performed can be `ls-refs`, `clone` or `fetch`.
2323 #[maybe_async]
24−pub async fn fetch<F, D, T>(
24+pub async fn fetch<F, D, T, B, P>(
2525 mut transport: T,
26− mut delegate: D,
26+ mut delegate: B,
2727 mut authenticate: F,
28− mut progress: impl Progress,
28+ mut progress: P,
2929 ) -> Result<(), Error>
3030 where
3131 F: FnMut(credentials::Action<'_>) -> credentials::Result,
3232 D: Delegate,
33+ B: BorrowMut<D>,
3334 T: client::Transport,
35+ P: Progress,
3436 {
3537 let (protocol_version, parsed_refs, capabilities) = {
3638 progress.init(None, progress::steps());
3739 progress.set_name("handshake");
3840 progress.step();
3941
40− let extra_parameters = delegate.handshake_extra_parameters();
42+ let extra_parameters = delegate.borrow_mut().handshake_extra_parameters();
4143 let extra_parameters: Vec<_> = extra_parameters
4244 .iter()
4345 .map(|(k, v)| (k.as_str(), v.as_ref().map(|s| s.as_str())))
@@ -114,7 +116,9 @@ where · 70 unmodified lines
114116 let ls_refs = Command::LsRefs;
115117 let mut ls_features = ls_refs.default_features(protocol_version, &capabilities);
116118 let mut ls_args = ls_refs.initial_arguments(&ls_features);
117− let next = delegate.prepare_ls_refs(&capabilities, &mut ls_args, &mut ls_features);
119+ let next = delegate
120+ .borrow_mut()
121+ .prepare_ls_refs(&capabilities, &mut ls_args, &mut ls_features);
118122 // User has requested to skip ls-refs, perhaps because they're using want-ref
119123 if next == LsRefsAction::Skip {
120124 vec![]
@@ -141,7 +145,9 @@ where · 20 unmodified lines
141145
142146 let fetch = Command::Fetch;
143147 let mut fetch_features = fetch.default_features(protocol_version, &capabilities);
144− let next = delegate.prepare_fetch(protocol_version, &capabilities, &mut fetch_features, &parsed_refs);
148+ let next = delegate
149+ .borrow_mut()
150+ .prepare_fetch(protocol_version, &capabilities, &mut fetch_features, &parsed_refs);
145151 fetch.validate_argument_prefixes_or_panic(protocol_version, &capabilities, &[], &fetch_features);
146152
147153 if next == Action::Cancel {
@@ -164,7 +170,9 @@ where · 16 unmodified lines
164170 progress.step();
165171 progress.set_name(format!("negotiate (round {})", round));
166172 round += 1;
167− let action = delegate.negotiate(&parsed_refs, &mut arguments, previous_response.as_ref());
173+ let action = delegate
174+ .borrow_mut()
175+ .negotiate(&parsed_refs, &mut arguments, previous_response.as_ref());
168176 let mut reader = arguments.send(&mut transport, action == Action::Cancel).await?;
169177 if sideband_all {
170178 setup_remote_progress(&mut progress, &mut reader);
@@ -176,7 +184,10 @@ where · 5 unmodified lines
176184 if !sideband_all {
177185 setup_remote_progress(&mut progress, &mut reader);
178186 }
179− delegate.receive_pack(reader, progress, &parsed_refs, &response).await?;
187+ delegate
188+ .borrow_mut()
189+ .receive_pack(reader, progress, &parsed_refs, &response)
190+ .await?;
180191 break 'negotiation;
181192 } else {
182193 match action {