pub struct RetriedStatsInfo { /* private fields */ }
Expand description

重试统计信息

Implementations§

提升当前终端地址的重试次数

Examples found in repository?
src/client/call/send_http_request.rs (line 100)
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
fn handle_response_error(
    mut response_error: ResponseError,
    http_parts: &mut HttpRequestParts,
    parts: &InnerRequestParts<'_>,
    retried: &mut RetriedStatsInfo,
) -> TryError {
    let retry_result = parts.http_client().request_retrier().retry(
        http_parts,
        RequestRetrierOptions::builder(&response_error, retried)
            .idempotent(parts.idempotent())
            .build(),
    );
    retried.increase_current_endpoint();
    response_error = response_error.set_retry_decision(retry_result.decision());
    TryError::new(response_error, retry_result)
}

提升放弃的终端地址的数量

Examples found in repository?
src/client/call/try_endpoints.rs (line 114)
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
    fn try_domain_with_port(
        domain_with_port: &DomainWithPort,
        tried_ips: &mut IpAddrsSet,
        parts: &InnerRequestParts<'_>,
        body: &mut SyncRequestBody<'_>,
        extensions: &mut Extensions,
        retried: &mut RetriedStatsInfo,
        is_endpoints_alternative: bool,
    ) -> Result<SyncResponse, ControlFlow<TryErrorWithExtensions>> {
        retried.switch_endpoint();
        return if parts.http_client().http_caller().is_resolved_ip_addrs_supported() {
            debug!("Try domain with resolver: {}", domain_with_port);
            with_resolver(
                domain_with_port,
                tried_ips,
                parts,
                body,
                extensions,
                retried,
                is_endpoints_alternative,
            )
        } else {
            debug!("Try domain without resolver: {}", domain_with_port);
            without_resolver(
                domain_with_port,
                parts,
                body,
                extensions,
                retried,
                is_endpoints_alternative,
            )
        }
        .tap_err(|_| retried.increase_abandoned_endpoints());

        fn with_resolver(
            domain_with_port: &DomainWithPort,
            tried_ips: &mut IpAddrsSet,
            parts: &InnerRequestParts<'_>,
            body: &mut SyncRequestBody<'_>,
            extensions: &mut Extensions,
            retried: &mut RetriedStatsInfo,
            is_endpoints_alternative: bool,
        ) -> Result<SyncResponse, ControlFlow<TryErrorWithExtensions>> {
            let mut last_error: Option<TryError> = None;
            let ips = resolve(parts, domain_with_port, extensions, retried)
                .map_err(|err| err.with_extensions(take(extensions)))
                .map_err(Some)
                .map_err(ControlFlow::TryNext)?;
            if !ips.is_empty() {
                let mut remaining_ips = {
                    let mut ips = IpAddrsSet::new(&ips);
                    ips.difference_set(tried_ips);
                    ips
                };
                loop {
                    match try_domain_with_ips(
                        domain_with_port,
                        &mut remaining_ips,
                        tried_ips,
                        parts,
                        body,
                        extensions,
                        retried,
                        is_endpoints_alternative,
                    ) {
                        Ok(response) => return Ok(response),
                        Err(TryFlow::TryNext(None)) => {
                            break;
                        }
                        Err(TryFlow::TryAgain(err)) => {
                            let (err, ext) = err.split();
                            *extensions = ext;
                            last_error = Some(err);
                        }
                        Err(TryFlow::DontRetry(err)) => {
                            return Err(ControlFlow::DontRetry(err));
                        }
                        Err(TryFlow::TryNext(Some(err))) => {
                            return Err(ControlFlow::TryNext(Some(err)));
                        }
                    }
                }
            }
            Err(ControlFlow::TryNext(
                last_error.map(|err| err.with_extensions(take(extensions))),
            ))
        }

        fn without_resolver(
            domain_with_port: &DomainWithPort,
            parts: &InnerRequestParts<'_>,
            body: &mut SyncRequestBody<'_>,
            extensions: &mut Extensions,
            retried: &mut RetriedStatsInfo,
            is_endpoints_alternative: bool,
        ) -> Result<SyncResponse, ControlFlow<TryErrorWithExtensions>> {
            let domain = DomainOrIpAddr::new_from_domain(domain_with_port.to_owned(), vec![]);
            match try_domain_or_ip_addr(&domain, parts, body, take(extensions), retried) {
                Ok(response) => Ok(response),
                Err(err) => match err.retry_decision() {
                    RetryDecision::TryAlternativeEndpoints if is_endpoints_alternative => {
                        Err(ControlFlow::DontRetry(err))
                    }
                    RetryDecision::DontRetry => {
                        retried.increase_abandoned_ips_of_current_endpoint();
                        Err(ControlFlow::DontRetry(err))
                    }
                    _ => {
                        retried.increase_abandoned_ips_of_current_endpoint();
                        Err(ControlFlow::TryNext(Some(err)))
                    }
                },
            }
        }

        #[allow(clippy::too_many_arguments)]
        fn try_domain_with_ips(
            domain_with_port: &DomainWithPort,
            remaining_ips: &mut IpAddrsSet,
            tried_ips: &mut IpAddrsSet,
            parts: &InnerRequestParts<'_>,
            body: &mut SyncRequestBody<'_>,
            extensions: &mut Extensions,
            retried: &mut RetriedStatsInfo,
            is_endpoints_alternative: bool,
        ) -> Result<SyncResponse, TryFlow<TryErrorWithExtensions>> {
            let chosen_ips = match remaining_ips.remains() {
                ips if !ips.is_empty() => choose(parts, &ips, extensions, retried)
                    .map_err(|err| err.with_extensions(take(extensions)))
                    .map_err(TryFlow::TryAgain)?,
                _ => vec![],
            };
            if chosen_ips.is_empty() {
                Err(TryFlow::TryNext(None))
            } else {
                remaining_ips.difference_slice(&chosen_ips);
                tried_ips.union_slice(&chosen_ips);
                retried.switch_ips();
                let chosen_ips = IpAddrs::from(chosen_ips);
                debug!("Try domain with IPs: {}({})", domain_with_port, chosen_ips);
                match try_domain_or_single_ip(
                    &DomainOrIpAddr::new_from_domain(domain_with_port.to_owned(), chosen_ips.into()),
                    parts,
                    body,
                    take(extensions),
                    retried,
                    is_endpoints_alternative,
                ) {
                    Ok(response) => Ok(response),
                    Err(SingleTryFlow::TryAgain(err)) => Err(TryFlow::TryAgain(err)),
                    Err(SingleTryFlow::DontRetry(err)) => Err(TryFlow::DontRetry(err)),
                }
            }
        }
    }

    fn try_ips(
        ips: &[IpAddrWithPort],
        tried_ips: &mut IpAddrsSet,
        parts: &InnerRequestParts<'_>,
        body: &mut SyncRequestBody<'_>,
        extensions: &mut Extensions,
        retried: &mut RetriedStatsInfo,
        is_endpoints_alternative: bool,
    ) -> Result<SyncResponse, ControlFlow<TryErrorWithExtensions>> {
        let mut last_error: Option<TryError> = None;

        let mut remaining_ips = {
            let mut ips = IpAddrsSet::new(ips);
            ips.difference_set(tried_ips);
            ips
        };
        loop {
            debug!("Try IPs: {}", remaining_ips);
            match try_remaining_ips(
                &mut remaining_ips,
                tried_ips,
                parts,
                body,
                extensions,
                retried,
                is_endpoints_alternative,
            ) {
                Ok(response) => return Ok(response),
                Err(ControlFlow::TryNext(Some(err))) => {
                    let (err, ext) = err.split();
                    *extensions = ext;
                    last_error = Some(err);
                }
                Err(ControlFlow::TryNext(None)) => {
                    break;
                }
                Err(err) => {
                    return Err(err);
                }
            }
        }
        return Err(ControlFlow::TryNext(
            last_error.map(|err| err.with_extensions(take(extensions))),
        ));

        fn try_remaining_ips(
            remaining_ips: &mut IpAddrsSet,
            tried_ips: &mut IpAddrsSet,
            parts: &InnerRequestParts<'_>,
            body: &mut SyncRequestBody<'_>,
            extensions: &mut Extensions,
            retried: &mut RetriedStatsInfo,
            is_endpoints_alternative: bool,
        ) -> Result<SyncResponse, ControlFlow<TryErrorWithExtensions>> {
            let mut last_error: Option<TryError> = None;
            let chosen_ips = match remaining_ips.remains() {
                ips if !ips.is_empty() => choose(parts, &ips, extensions, retried)
                    .map_err(|err| err.with_extensions(take(extensions)))
                    .map_err(Some)
                    .map_err(ControlFlow::TryNext)?,
                _ => vec![],
            };
            if !chosen_ips.is_empty() {
                remaining_ips.difference_slice(&chosen_ips);
                tried_ips.union_slice(&chosen_ips);
                for chosen_ip in chosen_ips.into_iter() {
                    retried.switch_endpoint();
                    debug!("Try single IP: {}", chosen_ip);
                    match try_single_ip(chosen_ip, parts, body, extensions, retried, is_endpoints_alternative) {
                        Ok(response) => return Ok(response),
                        Err(SingleTryFlow::TryAgain(err)) => {
                            let (err, ext) = err.split();
                            *extensions = ext;
                            last_error = Some(err);
                            retried.increase_abandoned_endpoints();
                        }
                        Err(SingleTryFlow::DontRetry(err)) => {
                            retried.increase_abandoned_endpoints();
                            return Err(ControlFlow::DontRetry(err));
                        }
                    }
                }
            }
            Err(ControlFlow::TryNext(
                last_error.map(|err| err.with_extensions(take(extensions))),
            ))
        }

        fn try_single_ip(
            ip: IpAddrWithPort,
            parts: &InnerRequestParts<'_>,
            body: &mut SyncRequestBody,
            extensions: &mut Extensions,
            retried: &mut RetriedStatsInfo,
            is_endpoints_alternative: bool,
        ) -> Result<SyncResponse, SingleTryFlow<TryErrorWithExtensions>> {
            try_domain_or_single_ip(
                &DomainOrIpAddr::from(ip),
                parts,
                body,
                take(extensions),
                retried,
                is_endpoints_alternative,
            )
        }
    }

    fn try_domain_or_single_ip(
        domain: &DomainOrIpAddr,
        parts: &InnerRequestParts<'_>,
        body: &mut SyncRequestBody<'_>,
        extensions: Extensions,
        retried: &mut RetriedStatsInfo,
        is_endpoints_alternative: bool,
    ) -> Result<SyncResponse, SingleTryFlow<TryErrorWithExtensions>> {
        match try_domain_or_ip_addr(domain, parts, body, extensions, retried) {
            Ok(response) => Ok(response),
            Err(err) => match err.retry_decision() {
                RetryDecision::TryAlternativeEndpoints if is_endpoints_alternative => {
                    Err(SingleTryFlow::DontRetry(err))
                }
                RetryDecision::DontRetry => {
                    retried.increase_abandoned_ips_of_current_endpoint();
                    Err(SingleTryFlow::DontRetry(err))
                }
                _ => {
                    retried.increase_abandoned_ips_of_current_endpoint();
                    Err(SingleTryFlow::TryAgain(err))
                }
            },
        }
    }
}

#[cfg(feature = "async")]
use super::{
    super::{AsyncRequestBody, AsyncResponse},
    try_domain_or_ip_addr::async_try_domain_or_ip_addr,
    utils::{async_choose, async_resolve},
};

#[cfg(feature = "async")]
pub(super) async fn async_try_endpoints(
    endpoints: &[Endpoint],
    parts: &InnerRequestParts<'_>,
    body: &mut AsyncRequestBody<'_>,
    mut extensions: Extensions,
    tried_ips: &mut IpAddrsSet,
    retried: &mut RetriedStatsInfo,
    is_endpoints_alternative: bool,
) -> Result<AsyncResponse, TryErrorWithExtensions> {
    let mut last_error: Option<TryError> = None;

    for domain_with_port in find_domains_with_port(endpoints) {
        debug!("Try domain with port: {}", domain_with_port);
        match try_domain_with_port(
            domain_with_port,
            tried_ips,
            parts,
            body,
            &mut extensions,
            retried,
            is_endpoints_alternative,
        )
        .await
        {
            Ok(response) => return Ok(response),
            Err(ControlFlow::TryNext(Some(err))) => {
                let (err, ext) = err.split();
                extensions = ext;
                last_error = Some(err);
            }
            Err(ControlFlow::TryNext(None)) => {}
            Err(ControlFlow::DontRetry(err)) => {
                return Err(err);
            }
        }
    }

    let ips = find_ip_addr_with_port(endpoints).copied().collect::<Vec<_>>();
    if !ips.is_empty() {
        debug!("Try IPs with port: {:?}", ips);
        match try_ips(
            &ips,
            tried_ips,
            parts,
            body,
            &mut extensions,
            retried,
            is_endpoints_alternative,
        )
        .await
        {
            Ok(response) => return Ok(response),
            Err(ControlFlow::TryNext(Some(err))) => {
                let (err, ext) = err.split();
                extensions = ext;
                last_error = Some(err);
            }
            Err(ControlFlow::TryNext(None)) => {}
            Err(ControlFlow::DontRetry(err)) => {
                return Err(err);
            }
        }
    }

    return Err(last_error
        .unwrap_or_else(|| no_try_error(retried))
        .with_extensions(extensions));

    async fn try_domain_with_port(
        domain_with_port: &DomainWithPort,
        tried_ips: &mut IpAddrsSet,
        parts: &InnerRequestParts<'_>,
        body: &mut AsyncRequestBody<'_>,
        extensions: &mut Extensions,
        retried: &mut RetriedStatsInfo,
        is_endpoints_alternative: bool,
    ) -> Result<AsyncResponse, ControlFlow<TryErrorWithExtensions>> {
        retried.switch_endpoint();
        return if parts.http_client().http_caller().is_resolved_ip_addrs_supported() {
            debug!("Try domain with resolver: {}", domain_with_port);
            with_resolver(
                domain_with_port,
                tried_ips,
                parts,
                body,
                extensions,
                retried,
                is_endpoints_alternative,
            )
            .await
        } else {
            debug!("Try domain without resolver: {}", domain_with_port);
            without_resolver(
                domain_with_port,
                parts,
                body,
                extensions,
                retried,
                is_endpoints_alternative,
            )
            .await
        }
        .tap_err(|_| retried.increase_abandoned_endpoints());

        async fn with_resolver(
            domain_with_port: &DomainWithPort,
            tried_ips: &mut IpAddrsSet,
            parts: &InnerRequestParts<'_>,
            body: &mut AsyncRequestBody<'_>,
            extensions: &mut Extensions,
            retried: &mut RetriedStatsInfo,
            is_endpoints_alternative: bool,
        ) -> Result<AsyncResponse, ControlFlow<TryErrorWithExtensions>> {
            let mut last_error: Option<TryError> = None;
            let ips = async_resolve(parts, domain_with_port, extensions, retried)
                .await
                .map_err(|err| err.with_extensions(take(extensions)))
                .map_err(Some)
                .map_err(ControlFlow::TryNext)?;
            if !ips.is_empty() {
                let mut remaining_ips = {
                    let mut ips = IpAddrsSet::new(&ips);
                    ips.difference_set(tried_ips);
                    ips
                };
                loop {
                    match try_domain_with_ips(
                        domain_with_port,
                        &mut remaining_ips,
                        tried_ips,
                        parts,
                        body,
                        extensions,
                        retried,
                        is_endpoints_alternative,
                    )
                    .await
                    {
                        Ok(response) => return Ok(response),
                        Err(TryFlow::TryNext(None)) => {
                            break;
                        }
                        Err(TryFlow::TryAgain(err)) => {
                            let (err, ext) = err.split();
                            *extensions = ext;
                            last_error = Some(err);
                        }
                        Err(TryFlow::DontRetry(err)) => {
                            return Err(ControlFlow::DontRetry(err));
                        }
                        Err(TryFlow::TryNext(Some(err))) => {
                            return Err(ControlFlow::TryNext(Some(err)));
                        }
                    }
                }
            }
            Err(ControlFlow::TryNext(
                last_error.map(|err| err.with_extensions(take(extensions))),
            ))
        }

        async fn without_resolver(
            domain_with_port: &DomainWithPort,
            parts: &InnerRequestParts<'_>,
            body: &mut AsyncRequestBody<'_>,
            extensions: &mut Extensions,
            retried: &mut RetriedStatsInfo,
            is_endpoints_alternative: bool,
        ) -> Result<AsyncResponse, ControlFlow<TryErrorWithExtensions>> {
            let domain = DomainOrIpAddr::new_from_domain(domain_with_port.to_owned(), vec![]);
            match async_try_domain_or_ip_addr(&domain, parts, body, take(extensions), retried).await {
                Ok(response) => Ok(response),
                Err(err) => match err.retry_decision() {
                    RetryDecision::TryAlternativeEndpoints if is_endpoints_alternative => {
                        Err(ControlFlow::DontRetry(err))
                    }
                    RetryDecision::DontRetry => {
                        retried.increase_abandoned_ips_of_current_endpoint();
                        Err(ControlFlow::DontRetry(err))
                    }
                    _ => {
                        retried.increase_abandoned_ips_of_current_endpoint();
                        Err(ControlFlow::TryNext(Some(err)))
                    }
                },
            }
        }

        #[allow(clippy::too_many_arguments)]
        async fn try_domain_with_ips(
            domain_with_port: &DomainWithPort,
            remaining_ips: &mut IpAddrsSet,
            tried_ips: &mut IpAddrsSet,
            parts: &InnerRequestParts<'_>,
            body: &mut AsyncRequestBody<'_>,
            extensions: &mut Extensions,
            retried: &mut RetriedStatsInfo,
            is_endpoints_alternative: bool,
        ) -> Result<AsyncResponse, TryFlow<TryErrorWithExtensions>> {
            let chosen_ips = match remaining_ips.remains() {
                ips if !ips.is_empty() => async_choose(parts, &ips, extensions, retried)
                    .await
                    .map_err(|err| err.with_extensions(take(extensions)))
                    .map_err(TryFlow::TryAgain)?,
                _ => vec![],
            };
            if chosen_ips.is_empty() {
                Err(TryFlow::TryNext(None))
            } else {
                remaining_ips.difference_slice(&chosen_ips);
                tried_ips.union_slice(&chosen_ips);
                retried.switch_ips();
                let chosen_ips = IpAddrs::from(chosen_ips);
                debug!("Try domain with IPs: {}({})", domain_with_port, chosen_ips);
                match try_domain_or_single_ip(
                    &DomainOrIpAddr::new_from_domain(domain_with_port.to_owned(), chosen_ips.into()),
                    parts,
                    body,
                    take(extensions),
                    retried,
                    is_endpoints_alternative,
                )
                .await
                {
                    Ok(response) => Ok(response),
                    Err(SingleTryFlow::TryAgain(err)) => Err(TryFlow::TryAgain(err)),
                    Err(SingleTryFlow::DontRetry(err)) => Err(TryFlow::DontRetry(err)),
                }
            }
        }
    }

    async fn try_ips(
        ips: &[IpAddrWithPort],
        tried_ips: &mut IpAddrsSet,
        parts: &InnerRequestParts<'_>,
        body: &mut AsyncRequestBody<'_>,
        extensions: &mut Extensions,
        retried: &mut RetriedStatsInfo,
        is_endpoints_alternative: bool,
    ) -> Result<AsyncResponse, ControlFlow<TryErrorWithExtensions>> {
        let mut last_error: Option<TryError> = None;

        let mut remaining_ips = {
            let mut ips = IpAddrsSet::new(ips);
            ips.difference_set(tried_ips);
            ips
        };
        loop {
            debug!("Try IPs: {}", remaining_ips);
            match try_remaining_ips(
                &mut remaining_ips,
                tried_ips,
                parts,
                body,
                extensions,
                retried,
                is_endpoints_alternative,
            )
            .await
            {
                Ok(response) => return Ok(response),
                Err(ControlFlow::TryNext(Some(err))) => {
                    let (err, ext) = err.split();
                    *extensions = ext;
                    last_error = Some(err);
                }
                Err(ControlFlow::TryNext(None)) => {
                    break;
                }
                Err(err) => {
                    return Err(err);
                }
            }
        }
        return Err(ControlFlow::TryNext(
            last_error.map(|err| err.with_extensions(take(extensions))),
        ));

        async fn try_remaining_ips(
            remaining_ips: &mut IpAddrsSet,
            tried_ips: &mut IpAddrsSet,
            parts: &InnerRequestParts<'_>,
            body: &mut AsyncRequestBody<'_>,
            extensions: &mut Extensions,
            retried: &mut RetriedStatsInfo,
            is_endpoints_alternative: bool,
        ) -> Result<AsyncResponse, ControlFlow<TryErrorWithExtensions>> {
            let mut last_error: Option<TryError> = None;
            let chosen_ips = match remaining_ips.remains() {
                ips if !ips.is_empty() => async_choose(parts, &ips, extensions, retried)
                    .await
                    .map_err(|err| err.with_extensions(take(extensions)))
                    .map_err(Some)
                    .map_err(ControlFlow::TryNext)?,
                _ => vec![],
            };
            if !chosen_ips.is_empty() {
                remaining_ips.difference_slice(&chosen_ips);
                tried_ips.union_slice(&chosen_ips);
                for chosen_ip in chosen_ips.into_iter() {
                    retried.switch_endpoint();
                    debug!("Try single IP: {}", chosen_ip);
                    match try_single_ip(chosen_ip, parts, body, extensions, retried, is_endpoints_alternative).await {
                        Ok(response) => return Ok(response),
                        Err(SingleTryFlow::TryAgain(err)) => {
                            let (err, ext) = err.split();
                            *extensions = ext;
                            last_error = Some(err);
                            retried.increase_abandoned_endpoints();
                        }
                        Err(SingleTryFlow::DontRetry(err)) => {
                            retried.increase_abandoned_endpoints();
                            return Err(ControlFlow::DontRetry(err));
                        }
                    }
                }
            }
            Err(ControlFlow::TryNext(
                last_error.map(|err| err.with_extensions(take(extensions))),
            ))
        }

提升放弃的终端的 IP 地址的数量

Examples found in repository?
src/client/call/try_endpoints.rs (line 186)
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
        fn without_resolver(
            domain_with_port: &DomainWithPort,
            parts: &InnerRequestParts<'_>,
            body: &mut SyncRequestBody<'_>,
            extensions: &mut Extensions,
            retried: &mut RetriedStatsInfo,
            is_endpoints_alternative: bool,
        ) -> Result<SyncResponse, ControlFlow<TryErrorWithExtensions>> {
            let domain = DomainOrIpAddr::new_from_domain(domain_with_port.to_owned(), vec![]);
            match try_domain_or_ip_addr(&domain, parts, body, take(extensions), retried) {
                Ok(response) => Ok(response),
                Err(err) => match err.retry_decision() {
                    RetryDecision::TryAlternativeEndpoints if is_endpoints_alternative => {
                        Err(ControlFlow::DontRetry(err))
                    }
                    RetryDecision::DontRetry => {
                        retried.increase_abandoned_ips_of_current_endpoint();
                        Err(ControlFlow::DontRetry(err))
                    }
                    _ => {
                        retried.increase_abandoned_ips_of_current_endpoint();
                        Err(ControlFlow::TryNext(Some(err)))
                    }
                },
            }
        }

        #[allow(clippy::too_many_arguments)]
        fn try_domain_with_ips(
            domain_with_port: &DomainWithPort,
            remaining_ips: &mut IpAddrsSet,
            tried_ips: &mut IpAddrsSet,
            parts: &InnerRequestParts<'_>,
            body: &mut SyncRequestBody<'_>,
            extensions: &mut Extensions,
            retried: &mut RetriedStatsInfo,
            is_endpoints_alternative: bool,
        ) -> Result<SyncResponse, TryFlow<TryErrorWithExtensions>> {
            let chosen_ips = match remaining_ips.remains() {
                ips if !ips.is_empty() => choose(parts, &ips, extensions, retried)
                    .map_err(|err| err.with_extensions(take(extensions)))
                    .map_err(TryFlow::TryAgain)?,
                _ => vec![],
            };
            if chosen_ips.is_empty() {
                Err(TryFlow::TryNext(None))
            } else {
                remaining_ips.difference_slice(&chosen_ips);
                tried_ips.union_slice(&chosen_ips);
                retried.switch_ips();
                let chosen_ips = IpAddrs::from(chosen_ips);
                debug!("Try domain with IPs: {}({})", domain_with_port, chosen_ips);
                match try_domain_or_single_ip(
                    &DomainOrIpAddr::new_from_domain(domain_with_port.to_owned(), chosen_ips.into()),
                    parts,
                    body,
                    take(extensions),
                    retried,
                    is_endpoints_alternative,
                ) {
                    Ok(response) => Ok(response),
                    Err(SingleTryFlow::TryAgain(err)) => Err(TryFlow::TryAgain(err)),
                    Err(SingleTryFlow::DontRetry(err)) => Err(TryFlow::DontRetry(err)),
                }
            }
        }
    }

    fn try_ips(
        ips: &[IpAddrWithPort],
        tried_ips: &mut IpAddrsSet,
        parts: &InnerRequestParts<'_>,
        body: &mut SyncRequestBody<'_>,
        extensions: &mut Extensions,
        retried: &mut RetriedStatsInfo,
        is_endpoints_alternative: bool,
    ) -> Result<SyncResponse, ControlFlow<TryErrorWithExtensions>> {
        let mut last_error: Option<TryError> = None;

        let mut remaining_ips = {
            let mut ips = IpAddrsSet::new(ips);
            ips.difference_set(tried_ips);
            ips
        };
        loop {
            debug!("Try IPs: {}", remaining_ips);
            match try_remaining_ips(
                &mut remaining_ips,
                tried_ips,
                parts,
                body,
                extensions,
                retried,
                is_endpoints_alternative,
            ) {
                Ok(response) => return Ok(response),
                Err(ControlFlow::TryNext(Some(err))) => {
                    let (err, ext) = err.split();
                    *extensions = ext;
                    last_error = Some(err);
                }
                Err(ControlFlow::TryNext(None)) => {
                    break;
                }
                Err(err) => {
                    return Err(err);
                }
            }
        }
        return Err(ControlFlow::TryNext(
            last_error.map(|err| err.with_extensions(take(extensions))),
        ));

        fn try_remaining_ips(
            remaining_ips: &mut IpAddrsSet,
            tried_ips: &mut IpAddrsSet,
            parts: &InnerRequestParts<'_>,
            body: &mut SyncRequestBody<'_>,
            extensions: &mut Extensions,
            retried: &mut RetriedStatsInfo,
            is_endpoints_alternative: bool,
        ) -> Result<SyncResponse, ControlFlow<TryErrorWithExtensions>> {
            let mut last_error: Option<TryError> = None;
            let chosen_ips = match remaining_ips.remains() {
                ips if !ips.is_empty() => choose(parts, &ips, extensions, retried)
                    .map_err(|err| err.with_extensions(take(extensions)))
                    .map_err(Some)
                    .map_err(ControlFlow::TryNext)?,
                _ => vec![],
            };
            if !chosen_ips.is_empty() {
                remaining_ips.difference_slice(&chosen_ips);
                tried_ips.union_slice(&chosen_ips);
                for chosen_ip in chosen_ips.into_iter() {
                    retried.switch_endpoint();
                    debug!("Try single IP: {}", chosen_ip);
                    match try_single_ip(chosen_ip, parts, body, extensions, retried, is_endpoints_alternative) {
                        Ok(response) => return Ok(response),
                        Err(SingleTryFlow::TryAgain(err)) => {
                            let (err, ext) = err.split();
                            *extensions = ext;
                            last_error = Some(err);
                            retried.increase_abandoned_endpoints();
                        }
                        Err(SingleTryFlow::DontRetry(err)) => {
                            retried.increase_abandoned_endpoints();
                            return Err(ControlFlow::DontRetry(err));
                        }
                    }
                }
            }
            Err(ControlFlow::TryNext(
                last_error.map(|err| err.with_extensions(take(extensions))),
            ))
        }

        fn try_single_ip(
            ip: IpAddrWithPort,
            parts: &InnerRequestParts<'_>,
            body: &mut SyncRequestBody,
            extensions: &mut Extensions,
            retried: &mut RetriedStatsInfo,
            is_endpoints_alternative: bool,
        ) -> Result<SyncResponse, SingleTryFlow<TryErrorWithExtensions>> {
            try_domain_or_single_ip(
                &DomainOrIpAddr::from(ip),
                parts,
                body,
                take(extensions),
                retried,
                is_endpoints_alternative,
            )
        }
    }

    fn try_domain_or_single_ip(
        domain: &DomainOrIpAddr,
        parts: &InnerRequestParts<'_>,
        body: &mut SyncRequestBody<'_>,
        extensions: Extensions,
        retried: &mut RetriedStatsInfo,
        is_endpoints_alternative: bool,
    ) -> Result<SyncResponse, SingleTryFlow<TryErrorWithExtensions>> {
        match try_domain_or_ip_addr(domain, parts, body, extensions, retried) {
            Ok(response) => Ok(response),
            Err(err) => match err.retry_decision() {
                RetryDecision::TryAlternativeEndpoints if is_endpoints_alternative => {
                    Err(SingleTryFlow::DontRetry(err))
                }
                RetryDecision::DontRetry => {
                    retried.increase_abandoned_ips_of_current_endpoint();
                    Err(SingleTryFlow::DontRetry(err))
                }
                _ => {
                    retried.increase_abandoned_ips_of_current_endpoint();
                    Err(SingleTryFlow::TryAgain(err))
                }
            },
        }
    }
}

#[cfg(feature = "async")]
use super::{
    super::{AsyncRequestBody, AsyncResponse},
    try_domain_or_ip_addr::async_try_domain_or_ip_addr,
    utils::{async_choose, async_resolve},
};

#[cfg(feature = "async")]
pub(super) async fn async_try_endpoints(
    endpoints: &[Endpoint],
    parts: &InnerRequestParts<'_>,
    body: &mut AsyncRequestBody<'_>,
    mut extensions: Extensions,
    tried_ips: &mut IpAddrsSet,
    retried: &mut RetriedStatsInfo,
    is_endpoints_alternative: bool,
) -> Result<AsyncResponse, TryErrorWithExtensions> {
    let mut last_error: Option<TryError> = None;

    for domain_with_port in find_domains_with_port(endpoints) {
        debug!("Try domain with port: {}", domain_with_port);
        match try_domain_with_port(
            domain_with_port,
            tried_ips,
            parts,
            body,
            &mut extensions,
            retried,
            is_endpoints_alternative,
        )
        .await
        {
            Ok(response) => return Ok(response),
            Err(ControlFlow::TryNext(Some(err))) => {
                let (err, ext) = err.split();
                extensions = ext;
                last_error = Some(err);
            }
            Err(ControlFlow::TryNext(None)) => {}
            Err(ControlFlow::DontRetry(err)) => {
                return Err(err);
            }
        }
    }

    let ips = find_ip_addr_with_port(endpoints).copied().collect::<Vec<_>>();
    if !ips.is_empty() {
        debug!("Try IPs with port: {:?}", ips);
        match try_ips(
            &ips,
            tried_ips,
            parts,
            body,
            &mut extensions,
            retried,
            is_endpoints_alternative,
        )
        .await
        {
            Ok(response) => return Ok(response),
            Err(ControlFlow::TryNext(Some(err))) => {
                let (err, ext) = err.split();
                extensions = ext;
                last_error = Some(err);
            }
            Err(ControlFlow::TryNext(None)) => {}
            Err(ControlFlow::DontRetry(err)) => {
                return Err(err);
            }
        }
    }

    return Err(last_error
        .unwrap_or_else(|| no_try_error(retried))
        .with_extensions(extensions));

    async fn try_domain_with_port(
        domain_with_port: &DomainWithPort,
        tried_ips: &mut IpAddrsSet,
        parts: &InnerRequestParts<'_>,
        body: &mut AsyncRequestBody<'_>,
        extensions: &mut Extensions,
        retried: &mut RetriedStatsInfo,
        is_endpoints_alternative: bool,
    ) -> Result<AsyncResponse, ControlFlow<TryErrorWithExtensions>> {
        retried.switch_endpoint();
        return if parts.http_client().http_caller().is_resolved_ip_addrs_supported() {
            debug!("Try domain with resolver: {}", domain_with_port);
            with_resolver(
                domain_with_port,
                tried_ips,
                parts,
                body,
                extensions,
                retried,
                is_endpoints_alternative,
            )
            .await
        } else {
            debug!("Try domain without resolver: {}", domain_with_port);
            without_resolver(
                domain_with_port,
                parts,
                body,
                extensions,
                retried,
                is_endpoints_alternative,
            )
            .await
        }
        .tap_err(|_| retried.increase_abandoned_endpoints());

        async fn with_resolver(
            domain_with_port: &DomainWithPort,
            tried_ips: &mut IpAddrsSet,
            parts: &InnerRequestParts<'_>,
            body: &mut AsyncRequestBody<'_>,
            extensions: &mut Extensions,
            retried: &mut RetriedStatsInfo,
            is_endpoints_alternative: bool,
        ) -> Result<AsyncResponse, ControlFlow<TryErrorWithExtensions>> {
            let mut last_error: Option<TryError> = None;
            let ips = async_resolve(parts, domain_with_port, extensions, retried)
                .await
                .map_err(|err| err.with_extensions(take(extensions)))
                .map_err(Some)
                .map_err(ControlFlow::TryNext)?;
            if !ips.is_empty() {
                let mut remaining_ips = {
                    let mut ips = IpAddrsSet::new(&ips);
                    ips.difference_set(tried_ips);
                    ips
                };
                loop {
                    match try_domain_with_ips(
                        domain_with_port,
                        &mut remaining_ips,
                        tried_ips,
                        parts,
                        body,
                        extensions,
                        retried,
                        is_endpoints_alternative,
                    )
                    .await
                    {
                        Ok(response) => return Ok(response),
                        Err(TryFlow::TryNext(None)) => {
                            break;
                        }
                        Err(TryFlow::TryAgain(err)) => {
                            let (err, ext) = err.split();
                            *extensions = ext;
                            last_error = Some(err);
                        }
                        Err(TryFlow::DontRetry(err)) => {
                            return Err(ControlFlow::DontRetry(err));
                        }
                        Err(TryFlow::TryNext(Some(err))) => {
                            return Err(ControlFlow::TryNext(Some(err)));
                        }
                    }
                }
            }
            Err(ControlFlow::TryNext(
                last_error.map(|err| err.with_extensions(take(extensions))),
            ))
        }

        async fn without_resolver(
            domain_with_port: &DomainWithPort,
            parts: &InnerRequestParts<'_>,
            body: &mut AsyncRequestBody<'_>,
            extensions: &mut Extensions,
            retried: &mut RetriedStatsInfo,
            is_endpoints_alternative: bool,
        ) -> Result<AsyncResponse, ControlFlow<TryErrorWithExtensions>> {
            let domain = DomainOrIpAddr::new_from_domain(domain_with_port.to_owned(), vec![]);
            match async_try_domain_or_ip_addr(&domain, parts, body, take(extensions), retried).await {
                Ok(response) => Ok(response),
                Err(err) => match err.retry_decision() {
                    RetryDecision::TryAlternativeEndpoints if is_endpoints_alternative => {
                        Err(ControlFlow::DontRetry(err))
                    }
                    RetryDecision::DontRetry => {
                        retried.increase_abandoned_ips_of_current_endpoint();
                        Err(ControlFlow::DontRetry(err))
                    }
                    _ => {
                        retried.increase_abandoned_ips_of_current_endpoint();
                        Err(ControlFlow::TryNext(Some(err)))
                    }
                },
            }
        }

        #[allow(clippy::too_many_arguments)]
        async fn try_domain_with_ips(
            domain_with_port: &DomainWithPort,
            remaining_ips: &mut IpAddrsSet,
            tried_ips: &mut IpAddrsSet,
            parts: &InnerRequestParts<'_>,
            body: &mut AsyncRequestBody<'_>,
            extensions: &mut Extensions,
            retried: &mut RetriedStatsInfo,
            is_endpoints_alternative: bool,
        ) -> Result<AsyncResponse, TryFlow<TryErrorWithExtensions>> {
            let chosen_ips = match remaining_ips.remains() {
                ips if !ips.is_empty() => async_choose(parts, &ips, extensions, retried)
                    .await
                    .map_err(|err| err.with_extensions(take(extensions)))
                    .map_err(TryFlow::TryAgain)?,
                _ => vec![],
            };
            if chosen_ips.is_empty() {
                Err(TryFlow::TryNext(None))
            } else {
                remaining_ips.difference_slice(&chosen_ips);
                tried_ips.union_slice(&chosen_ips);
                retried.switch_ips();
                let chosen_ips = IpAddrs::from(chosen_ips);
                debug!("Try domain with IPs: {}({})", domain_with_port, chosen_ips);
                match try_domain_or_single_ip(
                    &DomainOrIpAddr::new_from_domain(domain_with_port.to_owned(), chosen_ips.into()),
                    parts,
                    body,
                    take(extensions),
                    retried,
                    is_endpoints_alternative,
                )
                .await
                {
                    Ok(response) => Ok(response),
                    Err(SingleTryFlow::TryAgain(err)) => Err(TryFlow::TryAgain(err)),
                    Err(SingleTryFlow::DontRetry(err)) => Err(TryFlow::DontRetry(err)),
                }
            }
        }
    }

    async fn try_ips(
        ips: &[IpAddrWithPort],
        tried_ips: &mut IpAddrsSet,
        parts: &InnerRequestParts<'_>,
        body: &mut AsyncRequestBody<'_>,
        extensions: &mut Extensions,
        retried: &mut RetriedStatsInfo,
        is_endpoints_alternative: bool,
    ) -> Result<AsyncResponse, ControlFlow<TryErrorWithExtensions>> {
        let mut last_error: Option<TryError> = None;

        let mut remaining_ips = {
            let mut ips = IpAddrsSet::new(ips);
            ips.difference_set(tried_ips);
            ips
        };
        loop {
            debug!("Try IPs: {}", remaining_ips);
            match try_remaining_ips(
                &mut remaining_ips,
                tried_ips,
                parts,
                body,
                extensions,
                retried,
                is_endpoints_alternative,
            )
            .await
            {
                Ok(response) => return Ok(response),
                Err(ControlFlow::TryNext(Some(err))) => {
                    let (err, ext) = err.split();
                    *extensions = ext;
                    last_error = Some(err);
                }
                Err(ControlFlow::TryNext(None)) => {
                    break;
                }
                Err(err) => {
                    return Err(err);
                }
            }
        }
        return Err(ControlFlow::TryNext(
            last_error.map(|err| err.with_extensions(take(extensions))),
        ));

        async fn try_remaining_ips(
            remaining_ips: &mut IpAddrsSet,
            tried_ips: &mut IpAddrsSet,
            parts: &InnerRequestParts<'_>,
            body: &mut AsyncRequestBody<'_>,
            extensions: &mut Extensions,
            retried: &mut RetriedStatsInfo,
            is_endpoints_alternative: bool,
        ) -> Result<AsyncResponse, ControlFlow<TryErrorWithExtensions>> {
            let mut last_error: Option<TryError> = None;
            let chosen_ips = match remaining_ips.remains() {
                ips if !ips.is_empty() => async_choose(parts, &ips, extensions, retried)
                    .await
                    .map_err(|err| err.with_extensions(take(extensions)))
                    .map_err(Some)
                    .map_err(ControlFlow::TryNext)?,
                _ => vec![],
            };
            if !chosen_ips.is_empty() {
                remaining_ips.difference_slice(&chosen_ips);
                tried_ips.union_slice(&chosen_ips);
                for chosen_ip in chosen_ips.into_iter() {
                    retried.switch_endpoint();
                    debug!("Try single IP: {}", chosen_ip);
                    match try_single_ip(chosen_ip, parts, body, extensions, retried, is_endpoints_alternative).await {
                        Ok(response) => return Ok(response),
                        Err(SingleTryFlow::TryAgain(err)) => {
                            let (err, ext) = err.split();
                            *extensions = ext;
                            last_error = Some(err);
                            retried.increase_abandoned_endpoints();
                        }
                        Err(SingleTryFlow::DontRetry(err)) => {
                            retried.increase_abandoned_endpoints();
                            return Err(ControlFlow::DontRetry(err));
                        }
                    }
                }
            }
            Err(ControlFlow::TryNext(
                last_error.map(|err| err.with_extensions(take(extensions))),
            ))
        }

        async fn try_single_ip(
            ip: IpAddrWithPort,
            parts: &InnerRequestParts<'_>,
            body: &mut AsyncRequestBody<'_>,
            extensions: &mut Extensions,
            retried: &mut RetriedStatsInfo,
            is_endpoints_alternative: bool,
        ) -> Result<AsyncResponse, SingleTryFlow<TryErrorWithExtensions>> {
            try_domain_or_single_ip(
                &DomainOrIpAddr::from(ip),
                parts,
                body,
                take(extensions),
                retried,
                is_endpoints_alternative,
            )
            .await
        }
    }

    async fn try_domain_or_single_ip(
        domain: &DomainOrIpAddr,
        parts: &InnerRequestParts<'_>,
        body: &mut AsyncRequestBody<'_>,
        extensions: Extensions,
        retried: &mut RetriedStatsInfo,
        is_endpoints_alternative: bool,
    ) -> Result<AsyncResponse, SingleTryFlow<TryErrorWithExtensions>> {
        match async_try_domain_or_ip_addr(domain, parts, body, extensions, retried).await {
            Ok(response) => Ok(response),
            Err(err) => match err.retry_decision() {
                RetryDecision::TryAlternativeEndpoints if is_endpoints_alternative => {
                    Err(SingleTryFlow::DontRetry(err))
                }
                RetryDecision::DontRetry => {
                    retried.increase_abandoned_ips_of_current_endpoint();
                    Err(SingleTryFlow::DontRetry(err))
                }
                _ => {
                    retried.increase_abandoned_ips_of_current_endpoint();
                    Err(SingleTryFlow::TryAgain(err))
                }
            },
        }
    }

切换到备选终端地址

Examples found in repository?
src/client/call/request_call.rs (line 37)
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
pub(in super::super) fn request_call<E: EndpointsProvider>(
    request: SyncInnerRequest<'_, E>,
) -> ApiResult<SyncResponse> {
    let (parts, mut body, into_endpoints, service_name, extensions) = request.split();
    let options = EndpointsGetOptions::builder().service_names(service_name).build();
    let endpoints = into_endpoints.get_endpoints(options)?;
    let mut tried_ips = IpAddrsSet::default();
    let mut retried = RetriedStatsInfo::default();

    return match try_preferred_endpoints(
        endpoints.preferred(),
        &parts,
        &mut body,
        extensions,
        &mut tried_ips,
        &mut retried,
    ) {
        Ok(response) => Ok(response),
        Err(err)
            if err.retry_decision() == RetryDecision::TryAlternativeEndpoints
                && !endpoints.alternative().is_empty() =>
        {
            let (_, extensions) = err.split();
            retried.switch_to_alternative_endpoints();
            debug!("Switch to alternative endpoints");
            try_alternative_endpoints(
                endpoints.alternative(),
                &parts,
                &mut body,
                extensions,
                &mut tried_ips,
                &mut retried,
            )
        }
        Err(err) => Err(err.into_response_error()),
    };

    fn try_preferred_endpoints(
        endpoints: &[Endpoint],
        parts: &InnerRequestParts<'_>,
        body: &mut SyncRequestBody<'_>,
        extensions: Extensions,
        tried_ips: &mut IpAddrsSet,
        retried: &mut RetriedStatsInfo,
    ) -> Result<SyncResponse, TryErrorWithExtensions> {
        try_endpoints(endpoints, parts, body, extensions, tried_ips, retried, true)
    }

    fn try_alternative_endpoints(
        endpoints: &[Endpoint],
        parts: &InnerRequestParts<'_>,
        body: &mut SyncRequestBody<'_>,
        extensions: Extensions,
        tried_ips: &mut IpAddrsSet,
        retried: &mut RetriedStatsInfo,
    ) -> ApiResult<SyncResponse> {
        try_endpoints(endpoints, parts, body, extensions, tried_ips, retried, false)
            .map_err(|err| err.into_response_error())
    }
}

#[cfg(feature = "async")]
use super::{
    super::{request::AsyncInnerRequest, AsyncRequestBody, AsyncResponse},
    try_endpoints::async_try_endpoints,
};

#[cfg(feature = "async")]
pub(in super::super) async fn async_request_call<E: EndpointsProvider>(
    request: AsyncInnerRequest<'_, E>,
) -> ApiResult<AsyncResponse> {
    let (parts, mut body, into_endpoints, service_name, extensions) = request.split();
    let options = EndpointsGetOptions::builder().service_names(service_name).build();
    let endpoints = into_endpoints.async_get_endpoints(options).await?;
    let mut tried_ips = IpAddrsSet::default();
    let mut retried = RetriedStatsInfo::default();

    return match try_preferred_endpoints(
        endpoints.preferred(),
        &parts,
        &mut body,
        extensions,
        &mut tried_ips,
        &mut retried,
    )
    .await
    {
        Ok(response) => Ok(response),
        Err(err)
            if err.retry_decision() == RetryDecision::TryAlternativeEndpoints
                && !endpoints.alternative().is_empty() =>
        {
            let (_, extensions) = err.split();
            retried.switch_to_alternative_endpoints();
            debug!("Switch to alternative endpoints");
            try_alternative_endpoints(
                endpoints.alternative(),
                &parts,
                &mut body,
                extensions,
                &mut tried_ips,
                &mut retried,
            )
            .await
        }
        Err(err) => Err(err.into_response_error()),
    };

    async fn try_preferred_endpoints(
        endpoints: &[Endpoint],
        parts: &InnerRequestParts<'_>,
        body: &mut AsyncRequestBody<'_>,
        extensions: Extensions,
        tried_ips: &mut IpAddrsSet,
        retried: &mut RetriedStatsInfo,
    ) -> Result<AsyncResponse, TryErrorWithExtensions> {
        async_try_endpoints(endpoints, parts, body, extensions, tried_ips, retried, true).await
    }

    async fn try_alternative_endpoints(
        endpoints: &[Endpoint],
        parts: &InnerRequestParts<'_>,
        body: &mut AsyncRequestBody<'_>,
        extensions: Extensions,
        tried_ips: &mut IpAddrsSet,
        retried: &mut RetriedStatsInfo,
    ) -> ApiResult<AsyncResponse> {
        async_try_endpoints(endpoints, parts, body, extensions, tried_ips, retried, false)
            .await
            .map_err(|err| err.into_response_error())
    }
}

切换终端地址

Examples found in repository?
src/client/retried.rs (line 39)
37
38
39
40
    pub fn switch_to_alternative_endpoints(&mut self) {
        self.switched_to_alternative_endpoints = true;
        self.switch_endpoint();
    }
More examples
Hide additional examples
src/client/call/try_endpoints.rs (line 91)
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
    fn try_domain_with_port(
        domain_with_port: &DomainWithPort,
        tried_ips: &mut IpAddrsSet,
        parts: &InnerRequestParts<'_>,
        body: &mut SyncRequestBody<'_>,
        extensions: &mut Extensions,
        retried: &mut RetriedStatsInfo,
        is_endpoints_alternative: bool,
    ) -> Result<SyncResponse, ControlFlow<TryErrorWithExtensions>> {
        retried.switch_endpoint();
        return if parts.http_client().http_caller().is_resolved_ip_addrs_supported() {
            debug!("Try domain with resolver: {}", domain_with_port);
            with_resolver(
                domain_with_port,
                tried_ips,
                parts,
                body,
                extensions,
                retried,
                is_endpoints_alternative,
            )
        } else {
            debug!("Try domain without resolver: {}", domain_with_port);
            without_resolver(
                domain_with_port,
                parts,
                body,
                extensions,
                retried,
                is_endpoints_alternative,
            )
        }
        .tap_err(|_| retried.increase_abandoned_endpoints());

        fn with_resolver(
            domain_with_port: &DomainWithPort,
            tried_ips: &mut IpAddrsSet,
            parts: &InnerRequestParts<'_>,
            body: &mut SyncRequestBody<'_>,
            extensions: &mut Extensions,
            retried: &mut RetriedStatsInfo,
            is_endpoints_alternative: bool,
        ) -> Result<SyncResponse, ControlFlow<TryErrorWithExtensions>> {
            let mut last_error: Option<TryError> = None;
            let ips = resolve(parts, domain_with_port, extensions, retried)
                .map_err(|err| err.with_extensions(take(extensions)))
                .map_err(Some)
                .map_err(ControlFlow::TryNext)?;
            if !ips.is_empty() {
                let mut remaining_ips = {
                    let mut ips = IpAddrsSet::new(&ips);
                    ips.difference_set(tried_ips);
                    ips
                };
                loop {
                    match try_domain_with_ips(
                        domain_with_port,
                        &mut remaining_ips,
                        tried_ips,
                        parts,
                        body,
                        extensions,
                        retried,
                        is_endpoints_alternative,
                    ) {
                        Ok(response) => return Ok(response),
                        Err(TryFlow::TryNext(None)) => {
                            break;
                        }
                        Err(TryFlow::TryAgain(err)) => {
                            let (err, ext) = err.split();
                            *extensions = ext;
                            last_error = Some(err);
                        }
                        Err(TryFlow::DontRetry(err)) => {
                            return Err(ControlFlow::DontRetry(err));
                        }
                        Err(TryFlow::TryNext(Some(err))) => {
                            return Err(ControlFlow::TryNext(Some(err)));
                        }
                    }
                }
            }
            Err(ControlFlow::TryNext(
                last_error.map(|err| err.with_extensions(take(extensions))),
            ))
        }

        fn without_resolver(
            domain_with_port: &DomainWithPort,
            parts: &InnerRequestParts<'_>,
            body: &mut SyncRequestBody<'_>,
            extensions: &mut Extensions,
            retried: &mut RetriedStatsInfo,
            is_endpoints_alternative: bool,
        ) -> Result<SyncResponse, ControlFlow<TryErrorWithExtensions>> {
            let domain = DomainOrIpAddr::new_from_domain(domain_with_port.to_owned(), vec![]);
            match try_domain_or_ip_addr(&domain, parts, body, take(extensions), retried) {
                Ok(response) => Ok(response),
                Err(err) => match err.retry_decision() {
                    RetryDecision::TryAlternativeEndpoints if is_endpoints_alternative => {
                        Err(ControlFlow::DontRetry(err))
                    }
                    RetryDecision::DontRetry => {
                        retried.increase_abandoned_ips_of_current_endpoint();
                        Err(ControlFlow::DontRetry(err))
                    }
                    _ => {
                        retried.increase_abandoned_ips_of_current_endpoint();
                        Err(ControlFlow::TryNext(Some(err)))
                    }
                },
            }
        }

        #[allow(clippy::too_many_arguments)]
        fn try_domain_with_ips(
            domain_with_port: &DomainWithPort,
            remaining_ips: &mut IpAddrsSet,
            tried_ips: &mut IpAddrsSet,
            parts: &InnerRequestParts<'_>,
            body: &mut SyncRequestBody<'_>,
            extensions: &mut Extensions,
            retried: &mut RetriedStatsInfo,
            is_endpoints_alternative: bool,
        ) -> Result<SyncResponse, TryFlow<TryErrorWithExtensions>> {
            let chosen_ips = match remaining_ips.remains() {
                ips if !ips.is_empty() => choose(parts, &ips, extensions, retried)
                    .map_err(|err| err.with_extensions(take(extensions)))
                    .map_err(TryFlow::TryAgain)?,
                _ => vec![],
            };
            if chosen_ips.is_empty() {
                Err(TryFlow::TryNext(None))
            } else {
                remaining_ips.difference_slice(&chosen_ips);
                tried_ips.union_slice(&chosen_ips);
                retried.switch_ips();
                let chosen_ips = IpAddrs::from(chosen_ips);
                debug!("Try domain with IPs: {}({})", domain_with_port, chosen_ips);
                match try_domain_or_single_ip(
                    &DomainOrIpAddr::new_from_domain(domain_with_port.to_owned(), chosen_ips.into()),
                    parts,
                    body,
                    take(extensions),
                    retried,
                    is_endpoints_alternative,
                ) {
                    Ok(response) => Ok(response),
                    Err(SingleTryFlow::TryAgain(err)) => Err(TryFlow::TryAgain(err)),
                    Err(SingleTryFlow::DontRetry(err)) => Err(TryFlow::DontRetry(err)),
                }
            }
        }
    }

    fn try_ips(
        ips: &[IpAddrWithPort],
        tried_ips: &mut IpAddrsSet,
        parts: &InnerRequestParts<'_>,
        body: &mut SyncRequestBody<'_>,
        extensions: &mut Extensions,
        retried: &mut RetriedStatsInfo,
        is_endpoints_alternative: bool,
    ) -> Result<SyncResponse, ControlFlow<TryErrorWithExtensions>> {
        let mut last_error: Option<TryError> = None;

        let mut remaining_ips = {
            let mut ips = IpAddrsSet::new(ips);
            ips.difference_set(tried_ips);
            ips
        };
        loop {
            debug!("Try IPs: {}", remaining_ips);
            match try_remaining_ips(
                &mut remaining_ips,
                tried_ips,
                parts,
                body,
                extensions,
                retried,
                is_endpoints_alternative,
            ) {
                Ok(response) => return Ok(response),
                Err(ControlFlow::TryNext(Some(err))) => {
                    let (err, ext) = err.split();
                    *extensions = ext;
                    last_error = Some(err);
                }
                Err(ControlFlow::TryNext(None)) => {
                    break;
                }
                Err(err) => {
                    return Err(err);
                }
            }
        }
        return Err(ControlFlow::TryNext(
            last_error.map(|err| err.with_extensions(take(extensions))),
        ));

        fn try_remaining_ips(
            remaining_ips: &mut IpAddrsSet,
            tried_ips: &mut IpAddrsSet,
            parts: &InnerRequestParts<'_>,
            body: &mut SyncRequestBody<'_>,
            extensions: &mut Extensions,
            retried: &mut RetriedStatsInfo,
            is_endpoints_alternative: bool,
        ) -> Result<SyncResponse, ControlFlow<TryErrorWithExtensions>> {
            let mut last_error: Option<TryError> = None;
            let chosen_ips = match remaining_ips.remains() {
                ips if !ips.is_empty() => choose(parts, &ips, extensions, retried)
                    .map_err(|err| err.with_extensions(take(extensions)))
                    .map_err(Some)
                    .map_err(ControlFlow::TryNext)?,
                _ => vec![],
            };
            if !chosen_ips.is_empty() {
                remaining_ips.difference_slice(&chosen_ips);
                tried_ips.union_slice(&chosen_ips);
                for chosen_ip in chosen_ips.into_iter() {
                    retried.switch_endpoint();
                    debug!("Try single IP: {}", chosen_ip);
                    match try_single_ip(chosen_ip, parts, body, extensions, retried, is_endpoints_alternative) {
                        Ok(response) => return Ok(response),
                        Err(SingleTryFlow::TryAgain(err)) => {
                            let (err, ext) = err.split();
                            *extensions = ext;
                            last_error = Some(err);
                            retried.increase_abandoned_endpoints();
                        }
                        Err(SingleTryFlow::DontRetry(err)) => {
                            retried.increase_abandoned_endpoints();
                            return Err(ControlFlow::DontRetry(err));
                        }
                    }
                }
            }
            Err(ControlFlow::TryNext(
                last_error.map(|err| err.with_extensions(take(extensions))),
            ))
        }

        fn try_single_ip(
            ip: IpAddrWithPort,
            parts: &InnerRequestParts<'_>,
            body: &mut SyncRequestBody,
            extensions: &mut Extensions,
            retried: &mut RetriedStatsInfo,
            is_endpoints_alternative: bool,
        ) -> Result<SyncResponse, SingleTryFlow<TryErrorWithExtensions>> {
            try_domain_or_single_ip(
                &DomainOrIpAddr::from(ip),
                parts,
                body,
                take(extensions),
                retried,
                is_endpoints_alternative,
            )
        }
    }

    fn try_domain_or_single_ip(
        domain: &DomainOrIpAddr,
        parts: &InnerRequestParts<'_>,
        body: &mut SyncRequestBody<'_>,
        extensions: Extensions,
        retried: &mut RetriedStatsInfo,
        is_endpoints_alternative: bool,
    ) -> Result<SyncResponse, SingleTryFlow<TryErrorWithExtensions>> {
        match try_domain_or_ip_addr(domain, parts, body, extensions, retried) {
            Ok(response) => Ok(response),
            Err(err) => match err.retry_decision() {
                RetryDecision::TryAlternativeEndpoints if is_endpoints_alternative => {
                    Err(SingleTryFlow::DontRetry(err))
                }
                RetryDecision::DontRetry => {
                    retried.increase_abandoned_ips_of_current_endpoint();
                    Err(SingleTryFlow::DontRetry(err))
                }
                _ => {
                    retried.increase_abandoned_ips_of_current_endpoint();
                    Err(SingleTryFlow::TryAgain(err))
                }
            },
        }
    }
}

#[cfg(feature = "async")]
use super::{
    super::{AsyncRequestBody, AsyncResponse},
    try_domain_or_ip_addr::async_try_domain_or_ip_addr,
    utils::{async_choose, async_resolve},
};

#[cfg(feature = "async")]
pub(super) async fn async_try_endpoints(
    endpoints: &[Endpoint],
    parts: &InnerRequestParts<'_>,
    body: &mut AsyncRequestBody<'_>,
    mut extensions: Extensions,
    tried_ips: &mut IpAddrsSet,
    retried: &mut RetriedStatsInfo,
    is_endpoints_alternative: bool,
) -> Result<AsyncResponse, TryErrorWithExtensions> {
    let mut last_error: Option<TryError> = None;

    for domain_with_port in find_domains_with_port(endpoints) {
        debug!("Try domain with port: {}", domain_with_port);
        match try_domain_with_port(
            domain_with_port,
            tried_ips,
            parts,
            body,
            &mut extensions,
            retried,
            is_endpoints_alternative,
        )
        .await
        {
            Ok(response) => return Ok(response),
            Err(ControlFlow::TryNext(Some(err))) => {
                let (err, ext) = err.split();
                extensions = ext;
                last_error = Some(err);
            }
            Err(ControlFlow::TryNext(None)) => {}
            Err(ControlFlow::DontRetry(err)) => {
                return Err(err);
            }
        }
    }

    let ips = find_ip_addr_with_port(endpoints).copied().collect::<Vec<_>>();
    if !ips.is_empty() {
        debug!("Try IPs with port: {:?}", ips);
        match try_ips(
            &ips,
            tried_ips,
            parts,
            body,
            &mut extensions,
            retried,
            is_endpoints_alternative,
        )
        .await
        {
            Ok(response) => return Ok(response),
            Err(ControlFlow::TryNext(Some(err))) => {
                let (err, ext) = err.split();
                extensions = ext;
                last_error = Some(err);
            }
            Err(ControlFlow::TryNext(None)) => {}
            Err(ControlFlow::DontRetry(err)) => {
                return Err(err);
            }
        }
    }

    return Err(last_error
        .unwrap_or_else(|| no_try_error(retried))
        .with_extensions(extensions));

    async fn try_domain_with_port(
        domain_with_port: &DomainWithPort,
        tried_ips: &mut IpAddrsSet,
        parts: &InnerRequestParts<'_>,
        body: &mut AsyncRequestBody<'_>,
        extensions: &mut Extensions,
        retried: &mut RetriedStatsInfo,
        is_endpoints_alternative: bool,
    ) -> Result<AsyncResponse, ControlFlow<TryErrorWithExtensions>> {
        retried.switch_endpoint();
        return if parts.http_client().http_caller().is_resolved_ip_addrs_supported() {
            debug!("Try domain with resolver: {}", domain_with_port);
            with_resolver(
                domain_with_port,
                tried_ips,
                parts,
                body,
                extensions,
                retried,
                is_endpoints_alternative,
            )
            .await
        } else {
            debug!("Try domain without resolver: {}", domain_with_port);
            without_resolver(
                domain_with_port,
                parts,
                body,
                extensions,
                retried,
                is_endpoints_alternative,
            )
            .await
        }
        .tap_err(|_| retried.increase_abandoned_endpoints());

        async fn with_resolver(
            domain_with_port: &DomainWithPort,
            tried_ips: &mut IpAddrsSet,
            parts: &InnerRequestParts<'_>,
            body: &mut AsyncRequestBody<'_>,
            extensions: &mut Extensions,
            retried: &mut RetriedStatsInfo,
            is_endpoints_alternative: bool,
        ) -> Result<AsyncResponse, ControlFlow<TryErrorWithExtensions>> {
            let mut last_error: Option<TryError> = None;
            let ips = async_resolve(parts, domain_with_port, extensions, retried)
                .await
                .map_err(|err| err.with_extensions(take(extensions)))
                .map_err(Some)
                .map_err(ControlFlow::TryNext)?;
            if !ips.is_empty() {
                let mut remaining_ips = {
                    let mut ips = IpAddrsSet::new(&ips);
                    ips.difference_set(tried_ips);
                    ips
                };
                loop {
                    match try_domain_with_ips(
                        domain_with_port,
                        &mut remaining_ips,
                        tried_ips,
                        parts,
                        body,
                        extensions,
                        retried,
                        is_endpoints_alternative,
                    )
                    .await
                    {
                        Ok(response) => return Ok(response),
                        Err(TryFlow::TryNext(None)) => {
                            break;
                        }
                        Err(TryFlow::TryAgain(err)) => {
                            let (err, ext) = err.split();
                            *extensions = ext;
                            last_error = Some(err);
                        }
                        Err(TryFlow::DontRetry(err)) => {
                            return Err(ControlFlow::DontRetry(err));
                        }
                        Err(TryFlow::TryNext(Some(err))) => {
                            return Err(ControlFlow::TryNext(Some(err)));
                        }
                    }
                }
            }
            Err(ControlFlow::TryNext(
                last_error.map(|err| err.with_extensions(take(extensions))),
            ))
        }

        async fn without_resolver(
            domain_with_port: &DomainWithPort,
            parts: &InnerRequestParts<'_>,
            body: &mut AsyncRequestBody<'_>,
            extensions: &mut Extensions,
            retried: &mut RetriedStatsInfo,
            is_endpoints_alternative: bool,
        ) -> Result<AsyncResponse, ControlFlow<TryErrorWithExtensions>> {
            let domain = DomainOrIpAddr::new_from_domain(domain_with_port.to_owned(), vec![]);
            match async_try_domain_or_ip_addr(&domain, parts, body, take(extensions), retried).await {
                Ok(response) => Ok(response),
                Err(err) => match err.retry_decision() {
                    RetryDecision::TryAlternativeEndpoints if is_endpoints_alternative => {
                        Err(ControlFlow::DontRetry(err))
                    }
                    RetryDecision::DontRetry => {
                        retried.increase_abandoned_ips_of_current_endpoint();
                        Err(ControlFlow::DontRetry(err))
                    }
                    _ => {
                        retried.increase_abandoned_ips_of_current_endpoint();
                        Err(ControlFlow::TryNext(Some(err)))
                    }
                },
            }
        }

        #[allow(clippy::too_many_arguments)]
        async fn try_domain_with_ips(
            domain_with_port: &DomainWithPort,
            remaining_ips: &mut IpAddrsSet,
            tried_ips: &mut IpAddrsSet,
            parts: &InnerRequestParts<'_>,
            body: &mut AsyncRequestBody<'_>,
            extensions: &mut Extensions,
            retried: &mut RetriedStatsInfo,
            is_endpoints_alternative: bool,
        ) -> Result<AsyncResponse, TryFlow<TryErrorWithExtensions>> {
            let chosen_ips = match remaining_ips.remains() {
                ips if !ips.is_empty() => async_choose(parts, &ips, extensions, retried)
                    .await
                    .map_err(|err| err.with_extensions(take(extensions)))
                    .map_err(TryFlow::TryAgain)?,
                _ => vec![],
            };
            if chosen_ips.is_empty() {
                Err(TryFlow::TryNext(None))
            } else {
                remaining_ips.difference_slice(&chosen_ips);
                tried_ips.union_slice(&chosen_ips);
                retried.switch_ips();
                let chosen_ips = IpAddrs::from(chosen_ips);
                debug!("Try domain with IPs: {}({})", domain_with_port, chosen_ips);
                match try_domain_or_single_ip(
                    &DomainOrIpAddr::new_from_domain(domain_with_port.to_owned(), chosen_ips.into()),
                    parts,
                    body,
                    take(extensions),
                    retried,
                    is_endpoints_alternative,
                )
                .await
                {
                    Ok(response) => Ok(response),
                    Err(SingleTryFlow::TryAgain(err)) => Err(TryFlow::TryAgain(err)),
                    Err(SingleTryFlow::DontRetry(err)) => Err(TryFlow::DontRetry(err)),
                }
            }
        }
    }

    async fn try_ips(
        ips: &[IpAddrWithPort],
        tried_ips: &mut IpAddrsSet,
        parts: &InnerRequestParts<'_>,
        body: &mut AsyncRequestBody<'_>,
        extensions: &mut Extensions,
        retried: &mut RetriedStatsInfo,
        is_endpoints_alternative: bool,
    ) -> Result<AsyncResponse, ControlFlow<TryErrorWithExtensions>> {
        let mut last_error: Option<TryError> = None;

        let mut remaining_ips = {
            let mut ips = IpAddrsSet::new(ips);
            ips.difference_set(tried_ips);
            ips
        };
        loop {
            debug!("Try IPs: {}", remaining_ips);
            match try_remaining_ips(
                &mut remaining_ips,
                tried_ips,
                parts,
                body,
                extensions,
                retried,
                is_endpoints_alternative,
            )
            .await
            {
                Ok(response) => return Ok(response),
                Err(ControlFlow::TryNext(Some(err))) => {
                    let (err, ext) = err.split();
                    *extensions = ext;
                    last_error = Some(err);
                }
                Err(ControlFlow::TryNext(None)) => {
                    break;
                }
                Err(err) => {
                    return Err(err);
                }
            }
        }
        return Err(ControlFlow::TryNext(
            last_error.map(|err| err.with_extensions(take(extensions))),
        ));

        async fn try_remaining_ips(
            remaining_ips: &mut IpAddrsSet,
            tried_ips: &mut IpAddrsSet,
            parts: &InnerRequestParts<'_>,
            body: &mut AsyncRequestBody<'_>,
            extensions: &mut Extensions,
            retried: &mut RetriedStatsInfo,
            is_endpoints_alternative: bool,
        ) -> Result<AsyncResponse, ControlFlow<TryErrorWithExtensions>> {
            let mut last_error: Option<TryError> = None;
            let chosen_ips = match remaining_ips.remains() {
                ips if !ips.is_empty() => async_choose(parts, &ips, extensions, retried)
                    .await
                    .map_err(|err| err.with_extensions(take(extensions)))
                    .map_err(Some)
                    .map_err(ControlFlow::TryNext)?,
                _ => vec![],
            };
            if !chosen_ips.is_empty() {
                remaining_ips.difference_slice(&chosen_ips);
                tried_ips.union_slice(&chosen_ips);
                for chosen_ip in chosen_ips.into_iter() {
                    retried.switch_endpoint();
                    debug!("Try single IP: {}", chosen_ip);
                    match try_single_ip(chosen_ip, parts, body, extensions, retried, is_endpoints_alternative).await {
                        Ok(response) => return Ok(response),
                        Err(SingleTryFlow::TryAgain(err)) => {
                            let (err, ext) = err.split();
                            *extensions = ext;
                            last_error = Some(err);
                            retried.increase_abandoned_endpoints();
                        }
                        Err(SingleTryFlow::DontRetry(err)) => {
                            retried.increase_abandoned_endpoints();
                            return Err(ControlFlow::DontRetry(err));
                        }
                    }
                }
            }
            Err(ControlFlow::TryNext(
                last_error.map(|err| err.with_extensions(take(extensions))),
            ))
        }

切换当前 IP 地址

Examples found in repository?
src/client/retried.rs (line 46)
43
44
45
46
47
    pub fn switch_endpoint(&mut self) {
        self.retried_on_current_endpoint = 0;
        self.abandoned_ips_of_current_endpoint = 0;
        self.switch_ips();
    }
More examples
Hide additional examples
src/client/call/try_endpoints.rs (line 219)
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
        fn try_domain_with_ips(
            domain_with_port: &DomainWithPort,
            remaining_ips: &mut IpAddrsSet,
            tried_ips: &mut IpAddrsSet,
            parts: &InnerRequestParts<'_>,
            body: &mut SyncRequestBody<'_>,
            extensions: &mut Extensions,
            retried: &mut RetriedStatsInfo,
            is_endpoints_alternative: bool,
        ) -> Result<SyncResponse, TryFlow<TryErrorWithExtensions>> {
            let chosen_ips = match remaining_ips.remains() {
                ips if !ips.is_empty() => choose(parts, &ips, extensions, retried)
                    .map_err(|err| err.with_extensions(take(extensions)))
                    .map_err(TryFlow::TryAgain)?,
                _ => vec![],
            };
            if chosen_ips.is_empty() {
                Err(TryFlow::TryNext(None))
            } else {
                remaining_ips.difference_slice(&chosen_ips);
                tried_ips.union_slice(&chosen_ips);
                retried.switch_ips();
                let chosen_ips = IpAddrs::from(chosen_ips);
                debug!("Try domain with IPs: {}({})", domain_with_port, chosen_ips);
                match try_domain_or_single_ip(
                    &DomainOrIpAddr::new_from_domain(domain_with_port.to_owned(), chosen_ips.into()),
                    parts,
                    body,
                    take(extensions),
                    retried,
                    is_endpoints_alternative,
                ) {
                    Ok(response) => Ok(response),
                    Err(SingleTryFlow::TryAgain(err)) => Err(TryFlow::TryAgain(err)),
                    Err(SingleTryFlow::DontRetry(err)) => Err(TryFlow::DontRetry(err)),
                }
            }
        }
    }

    fn try_ips(
        ips: &[IpAddrWithPort],
        tried_ips: &mut IpAddrsSet,
        parts: &InnerRequestParts<'_>,
        body: &mut SyncRequestBody<'_>,
        extensions: &mut Extensions,
        retried: &mut RetriedStatsInfo,
        is_endpoints_alternative: bool,
    ) -> Result<SyncResponse, ControlFlow<TryErrorWithExtensions>> {
        let mut last_error: Option<TryError> = None;

        let mut remaining_ips = {
            let mut ips = IpAddrsSet::new(ips);
            ips.difference_set(tried_ips);
            ips
        };
        loop {
            debug!("Try IPs: {}", remaining_ips);
            match try_remaining_ips(
                &mut remaining_ips,
                tried_ips,
                parts,
                body,
                extensions,
                retried,
                is_endpoints_alternative,
            ) {
                Ok(response) => return Ok(response),
                Err(ControlFlow::TryNext(Some(err))) => {
                    let (err, ext) = err.split();
                    *extensions = ext;
                    last_error = Some(err);
                }
                Err(ControlFlow::TryNext(None)) => {
                    break;
                }
                Err(err) => {
                    return Err(err);
                }
            }
        }
        return Err(ControlFlow::TryNext(
            last_error.map(|err| err.with_extensions(take(extensions))),
        ));

        fn try_remaining_ips(
            remaining_ips: &mut IpAddrsSet,
            tried_ips: &mut IpAddrsSet,
            parts: &InnerRequestParts<'_>,
            body: &mut SyncRequestBody<'_>,
            extensions: &mut Extensions,
            retried: &mut RetriedStatsInfo,
            is_endpoints_alternative: bool,
        ) -> Result<SyncResponse, ControlFlow<TryErrorWithExtensions>> {
            let mut last_error: Option<TryError> = None;
            let chosen_ips = match remaining_ips.remains() {
                ips if !ips.is_empty() => choose(parts, &ips, extensions, retried)
                    .map_err(|err| err.with_extensions(take(extensions)))
                    .map_err(Some)
                    .map_err(ControlFlow::TryNext)?,
                _ => vec![],
            };
            if !chosen_ips.is_empty() {
                remaining_ips.difference_slice(&chosen_ips);
                tried_ips.union_slice(&chosen_ips);
                for chosen_ip in chosen_ips.into_iter() {
                    retried.switch_endpoint();
                    debug!("Try single IP: {}", chosen_ip);
                    match try_single_ip(chosen_ip, parts, body, extensions, retried, is_endpoints_alternative) {
                        Ok(response) => return Ok(response),
                        Err(SingleTryFlow::TryAgain(err)) => {
                            let (err, ext) = err.split();
                            *extensions = ext;
                            last_error = Some(err);
                            retried.increase_abandoned_endpoints();
                        }
                        Err(SingleTryFlow::DontRetry(err)) => {
                            retried.increase_abandoned_endpoints();
                            return Err(ControlFlow::DontRetry(err));
                        }
                    }
                }
            }
            Err(ControlFlow::TryNext(
                last_error.map(|err| err.with_extensions(take(extensions))),
            ))
        }

        fn try_single_ip(
            ip: IpAddrWithPort,
            parts: &InnerRequestParts<'_>,
            body: &mut SyncRequestBody,
            extensions: &mut Extensions,
            retried: &mut RetriedStatsInfo,
            is_endpoints_alternative: bool,
        ) -> Result<SyncResponse, SingleTryFlow<TryErrorWithExtensions>> {
            try_domain_or_single_ip(
                &DomainOrIpAddr::from(ip),
                parts,
                body,
                take(extensions),
                retried,
                is_endpoints_alternative,
            )
        }
    }

    fn try_domain_or_single_ip(
        domain: &DomainOrIpAddr,
        parts: &InnerRequestParts<'_>,
        body: &mut SyncRequestBody<'_>,
        extensions: Extensions,
        retried: &mut RetriedStatsInfo,
        is_endpoints_alternative: bool,
    ) -> Result<SyncResponse, SingleTryFlow<TryErrorWithExtensions>> {
        match try_domain_or_ip_addr(domain, parts, body, extensions, retried) {
            Ok(response) => Ok(response),
            Err(err) => match err.retry_decision() {
                RetryDecision::TryAlternativeEndpoints if is_endpoints_alternative => {
                    Err(SingleTryFlow::DontRetry(err))
                }
                RetryDecision::DontRetry => {
                    retried.increase_abandoned_ips_of_current_endpoint();
                    Err(SingleTryFlow::DontRetry(err))
                }
                _ => {
                    retried.increase_abandoned_ips_of_current_endpoint();
                    Err(SingleTryFlow::TryAgain(err))
                }
            },
        }
    }
}

#[cfg(feature = "async")]
use super::{
    super::{AsyncRequestBody, AsyncResponse},
    try_domain_or_ip_addr::async_try_domain_or_ip_addr,
    utils::{async_choose, async_resolve},
};

#[cfg(feature = "async")]
pub(super) async fn async_try_endpoints(
    endpoints: &[Endpoint],
    parts: &InnerRequestParts<'_>,
    body: &mut AsyncRequestBody<'_>,
    mut extensions: Extensions,
    tried_ips: &mut IpAddrsSet,
    retried: &mut RetriedStatsInfo,
    is_endpoints_alternative: bool,
) -> Result<AsyncResponse, TryErrorWithExtensions> {
    let mut last_error: Option<TryError> = None;

    for domain_with_port in find_domains_with_port(endpoints) {
        debug!("Try domain with port: {}", domain_with_port);
        match try_domain_with_port(
            domain_with_port,
            tried_ips,
            parts,
            body,
            &mut extensions,
            retried,
            is_endpoints_alternative,
        )
        .await
        {
            Ok(response) => return Ok(response),
            Err(ControlFlow::TryNext(Some(err))) => {
                let (err, ext) = err.split();
                extensions = ext;
                last_error = Some(err);
            }
            Err(ControlFlow::TryNext(None)) => {}
            Err(ControlFlow::DontRetry(err)) => {
                return Err(err);
            }
        }
    }

    let ips = find_ip_addr_with_port(endpoints).copied().collect::<Vec<_>>();
    if !ips.is_empty() {
        debug!("Try IPs with port: {:?}", ips);
        match try_ips(
            &ips,
            tried_ips,
            parts,
            body,
            &mut extensions,
            retried,
            is_endpoints_alternative,
        )
        .await
        {
            Ok(response) => return Ok(response),
            Err(ControlFlow::TryNext(Some(err))) => {
                let (err, ext) = err.split();
                extensions = ext;
                last_error = Some(err);
            }
            Err(ControlFlow::TryNext(None)) => {}
            Err(ControlFlow::DontRetry(err)) => {
                return Err(err);
            }
        }
    }

    return Err(last_error
        .unwrap_or_else(|| no_try_error(retried))
        .with_extensions(extensions));

    async fn try_domain_with_port(
        domain_with_port: &DomainWithPort,
        tried_ips: &mut IpAddrsSet,
        parts: &InnerRequestParts<'_>,
        body: &mut AsyncRequestBody<'_>,
        extensions: &mut Extensions,
        retried: &mut RetriedStatsInfo,
        is_endpoints_alternative: bool,
    ) -> Result<AsyncResponse, ControlFlow<TryErrorWithExtensions>> {
        retried.switch_endpoint();
        return if parts.http_client().http_caller().is_resolved_ip_addrs_supported() {
            debug!("Try domain with resolver: {}", domain_with_port);
            with_resolver(
                domain_with_port,
                tried_ips,
                parts,
                body,
                extensions,
                retried,
                is_endpoints_alternative,
            )
            .await
        } else {
            debug!("Try domain without resolver: {}", domain_with_port);
            without_resolver(
                domain_with_port,
                parts,
                body,
                extensions,
                retried,
                is_endpoints_alternative,
            )
            .await
        }
        .tap_err(|_| retried.increase_abandoned_endpoints());

        async fn with_resolver(
            domain_with_port: &DomainWithPort,
            tried_ips: &mut IpAddrsSet,
            parts: &InnerRequestParts<'_>,
            body: &mut AsyncRequestBody<'_>,
            extensions: &mut Extensions,
            retried: &mut RetriedStatsInfo,
            is_endpoints_alternative: bool,
        ) -> Result<AsyncResponse, ControlFlow<TryErrorWithExtensions>> {
            let mut last_error: Option<TryError> = None;
            let ips = async_resolve(parts, domain_with_port, extensions, retried)
                .await
                .map_err(|err| err.with_extensions(take(extensions)))
                .map_err(Some)
                .map_err(ControlFlow::TryNext)?;
            if !ips.is_empty() {
                let mut remaining_ips = {
                    let mut ips = IpAddrsSet::new(&ips);
                    ips.difference_set(tried_ips);
                    ips
                };
                loop {
                    match try_domain_with_ips(
                        domain_with_port,
                        &mut remaining_ips,
                        tried_ips,
                        parts,
                        body,
                        extensions,
                        retried,
                        is_endpoints_alternative,
                    )
                    .await
                    {
                        Ok(response) => return Ok(response),
                        Err(TryFlow::TryNext(None)) => {
                            break;
                        }
                        Err(TryFlow::TryAgain(err)) => {
                            let (err, ext) = err.split();
                            *extensions = ext;
                            last_error = Some(err);
                        }
                        Err(TryFlow::DontRetry(err)) => {
                            return Err(ControlFlow::DontRetry(err));
                        }
                        Err(TryFlow::TryNext(Some(err))) => {
                            return Err(ControlFlow::TryNext(Some(err)));
                        }
                    }
                }
            }
            Err(ControlFlow::TryNext(
                last_error.map(|err| err.with_extensions(take(extensions))),
            ))
        }

        async fn without_resolver(
            domain_with_port: &DomainWithPort,
            parts: &InnerRequestParts<'_>,
            body: &mut AsyncRequestBody<'_>,
            extensions: &mut Extensions,
            retried: &mut RetriedStatsInfo,
            is_endpoints_alternative: bool,
        ) -> Result<AsyncResponse, ControlFlow<TryErrorWithExtensions>> {
            let domain = DomainOrIpAddr::new_from_domain(domain_with_port.to_owned(), vec![]);
            match async_try_domain_or_ip_addr(&domain, parts, body, take(extensions), retried).await {
                Ok(response) => Ok(response),
                Err(err) => match err.retry_decision() {
                    RetryDecision::TryAlternativeEndpoints if is_endpoints_alternative => {
                        Err(ControlFlow::DontRetry(err))
                    }
                    RetryDecision::DontRetry => {
                        retried.increase_abandoned_ips_of_current_endpoint();
                        Err(ControlFlow::DontRetry(err))
                    }
                    _ => {
                        retried.increase_abandoned_ips_of_current_endpoint();
                        Err(ControlFlow::TryNext(Some(err)))
                    }
                },
            }
        }

        #[allow(clippy::too_many_arguments)]
        async fn try_domain_with_ips(
            domain_with_port: &DomainWithPort,
            remaining_ips: &mut IpAddrsSet,
            tried_ips: &mut IpAddrsSet,
            parts: &InnerRequestParts<'_>,
            body: &mut AsyncRequestBody<'_>,
            extensions: &mut Extensions,
            retried: &mut RetriedStatsInfo,
            is_endpoints_alternative: bool,
        ) -> Result<AsyncResponse, TryFlow<TryErrorWithExtensions>> {
            let chosen_ips = match remaining_ips.remains() {
                ips if !ips.is_empty() => async_choose(parts, &ips, extensions, retried)
                    .await
                    .map_err(|err| err.with_extensions(take(extensions)))
                    .map_err(TryFlow::TryAgain)?,
                _ => vec![],
            };
            if chosen_ips.is_empty() {
                Err(TryFlow::TryNext(None))
            } else {
                remaining_ips.difference_slice(&chosen_ips);
                tried_ips.union_slice(&chosen_ips);
                retried.switch_ips();
                let chosen_ips = IpAddrs::from(chosen_ips);
                debug!("Try domain with IPs: {}({})", domain_with_port, chosen_ips);
                match try_domain_or_single_ip(
                    &DomainOrIpAddr::new_from_domain(domain_with_port.to_owned(), chosen_ips.into()),
                    parts,
                    body,
                    take(extensions),
                    retried,
                    is_endpoints_alternative,
                )
                .await
                {
                    Ok(response) => Ok(response),
                    Err(SingleTryFlow::TryAgain(err)) => Err(TryFlow::TryAgain(err)),
                    Err(SingleTryFlow::DontRetry(err)) => Err(TryFlow::DontRetry(err)),
                }
            }
        }

获取总共重试的次数

Examples found in repository?
src/client/backoff/exponential.rs (line 42)
40
41
42
43
44
45
46
47
    fn time(&self, _request: &mut HttpRequestParts, opts: BackoffOptions) -> GotBackoffDuration {
        let retried_count = if opts.retry_decision() == RetryDecision::Throttled {
            opts.retried().retried_total()
        } else {
            opts.retried().retried_on_current_endpoint()
        };
        GotBackoffDuration::from(self.base_delay * self.base_number.pow(retried_count as u32))
    }
More examples
Hide additional examples
src/client/retrier/limited.rs (line 28)
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
    fn retry(self, decision: RetryDecision, retries: usize, opts: RequestRetrierOptions) -> RetryDecision {
        match self {
            Self::LimitCurrentEndpoint => match decision {
                RetryDecision::RetryRequest | RetryDecision::Throttled
                    if opts.retried().retried_on_current_endpoint() >= retries =>
                {
                    RetryDecision::TryNextServer
                }
                result => result,
            },
            Self::LimitTotal => match decision {
                RetryDecision::RetryRequest | RetryDecision::Throttled if opts.retried().retried_total() >= retries => {
                    RetryDecision::DontRetry
                }
                result => result,
            },
        }
    }

获取当前终端地址的重试次数

Examples found in repository?
src/client/backoff/exponential.rs (line 44)
40
41
42
43
44
45
46
47
    fn time(&self, _request: &mut HttpRequestParts, opts: BackoffOptions) -> GotBackoffDuration {
        let retried_count = if opts.retry_decision() == RetryDecision::Throttled {
            opts.retried().retried_total()
        } else {
            opts.retried().retried_on_current_endpoint()
        };
        GotBackoffDuration::from(self.base_delay * self.base_number.pow(retried_count as u32))
    }
More examples
Hide additional examples
src/client/retrier/limited.rs (line 21)
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
    fn retry(self, decision: RetryDecision, retries: usize, opts: RequestRetrierOptions) -> RetryDecision {
        match self {
            Self::LimitCurrentEndpoint => match decision {
                RetryDecision::RetryRequest | RetryDecision::Throttled
                    if opts.retried().retried_on_current_endpoint() >= retries =>
                {
                    RetryDecision::TryNextServer
                }
                result => result,
            },
            Self::LimitTotal => match decision {
                RetryDecision::RetryRequest | RetryDecision::Throttled if opts.retried().retried_total() >= retries => {
                    RetryDecision::DontRetry
                }
                result => result,
            },
        }
    }

获取当前 IP 地址的重试次数

获取放弃的终端地址的数量

获取放弃的终端的 IP 地址的数量

是否切换到了备选终端地址

Trait Implementations§

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Returns the “default value” for a type. Read more
Formats the value using the given formatter. Read more
This method tests for self and other values to be equal, and is used by ==.
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more
Converts self into T using Into<T>. Read more
Compare self to key and return true if they are equal.

Returns the argument unchanged.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Pipes by value. This is generally the method you want to use. Read more
Borrows self and passes that borrow into the pipe function. Read more
Mutably borrows self and passes that borrow into the pipe function. Read more
Borrows self, then passes self.borrow() into the pipe function. Read more
Mutably borrows self, then passes self.borrow_mut() into the pipe function. Read more
Borrows self, then passes self.as_ref() into the pipe function.
Mutably borrows self, then passes self.as_mut() into the pipe function.
Borrows self, then passes self.deref() into the pipe function.
Mutably borrows self, then passes self.deref_mut() into the pipe function.
Should always be Self
Immutable access to a value. Read more
Mutable access to a value. Read more
Immutable access to the Borrow<B> of a value. Read more
Mutable access to the BorrowMut<B> of a value. Read more
Immutable access to the AsRef<R> view of a value. Read more
Mutable access to the AsMut<R> view of a value. Read more
Immutable access to the Deref::Target of a value. Read more
Mutable access to the Deref::Target of a value. Read more
Calls .tap() only in debug builds, and is erased in release builds.
Calls .tap_mut() only in debug builds, and is erased in release builds.
Calls .tap_borrow() only in debug builds, and is erased in release builds.
Calls .tap_borrow_mut() only in debug builds, and is erased in release builds.
Calls .tap_ref() only in debug builds, and is erased in release builds.
Calls .tap_ref_mut() only in debug builds, and is erased in release builds.
Calls .tap_deref() only in debug builds, and is erased in release builds.
Calls .tap_deref_mut() only in debug builds, and is erased in release builds.
The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
Converts the given value to a String. Read more
Attempts to convert self into T using TryInto<T>. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more