Skip to content

Commit ed93a96

Browse files
authored
refactor: make RetryConfig::max_attempts field a NonZeroU32 as well (#223)
1 parent 02e58b5 commit ed93a96

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/types.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ pub struct RetryConfig {
153153
/// Total number of attempts including the initial try. A value of `1` means no retries.
154154
///
155155
/// Defaults to `3`.
156-
pub max_attempts: u32,
156+
pub max_attempts: NonZeroU32,
157157
/// Minimum base delay for retries.
158158
///
159159
/// Defaults to `100ms`.
@@ -172,7 +172,7 @@ pub struct RetryConfig {
172172
impl Default for RetryConfig {
173173
fn default() -> Self {
174174
Self {
175-
max_attempts: 3,
175+
max_attempts: NonZeroU32::new(3).expect("valid non-zero u32"),
176176
min_base_delay: Duration::from_millis(100),
177177
max_base_delay: Duration::from_secs(1),
178178
append_retry_policy: AppendRetryPolicy::All,
@@ -187,13 +187,13 @@ impl RetryConfig {
187187
}
188188

189189
pub(crate) fn max_retries(&self) -> u32 {
190-
self.max_attempts - 1
190+
self.max_attempts.get() - 1
191191
}
192192

193193
/// Set the total number of attempts including the initial try.
194194
pub fn with_max_attempts(self, max_attempts: NonZeroU32) -> Self {
195195
Self {
196-
max_attempts: max_attempts.get(),
196+
max_attempts,
197197
..self
198198
}
199199
}

0 commit comments

Comments
 (0)