google_cloud_gax/throttle_result.rs
1// Copyright 2025 Google LLC
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// https://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15//! Defines types related to throttling the retry loop.
16
17use crate::error::Error;
18
19/// The result of a retry throttling control decision.
20///
21/// The client libraries retry loop may throttle some retry attempts, that is,
22/// the request previously failed, it is retryable, but the policies in the
23/// loop have reached some limit or budget on the number of retry attempts. In
24/// such cases the retry attempt is not started, and the retry policy is
25/// consulted to determine if the retry loop should continue.
26///
27/// The retry policy receives the previous error, and should return whether the
28/// loop continues after the throttled attempt.
29///
30/// # Example
31///
32/// ```
33/// # use google_cloud_gax::{error::Error, retry_policy::RetryPolicy};
34/// # use google_cloud_gax::retry_state::RetryState;
35/// # use google_cloud_gax::{retry_result::RetryResult, throttle_result::ThrottleResult};
36/// #[derive(Debug)]
37/// struct MyRetryPolicy;
38/// impl google_cloud_gax::retry_policy::RetryPolicy for MyRetryPolicy {
39/// fn on_throttle(&self, state: &RetryState, error: Error) -> ThrottleResult {
40/// // Always stop the loop
41/// ThrottleResult::Exhausted(error)
42/// }
43/// fn on_error(&self, state: &RetryState, error: Error) -> RetryResult {
44/// # panic!();
45/// }
46/// }
47/// ```
48#[derive(Debug)]
49#[allow(clippy::exhaustive_enums)]
50pub enum ThrottleResult {
51 /// The error is retryable, but the policy is stopping the loop.
52 ///
53 /// Loop control policies may stop the loop on retryable errors, for
54 /// example, because the policy only allows a limited number of attempts.
55 Exhausted(Error),
56
57 /// The error was retryable, continue the loop.
58 Continue(Error),
59}