pub struct RecoveryPolicy { /* private fields */ }Expand description
Error recovery policy.
§Examples
use pmcp::error::{recovery::RecoveryPolicy, ErrorCode};
use pmcp::error::recovery::RecoveryStrategy;
use std::time::Duration;
// Create a default policy
let default_policy = RecoveryPolicy::default();
// Create custom policy
let mut policy = RecoveryPolicy::new(
RecoveryStrategy::RetryFixed {
attempts: 2,
delay: Duration::from_secs(1),
}
);
// Add strategy for specific error
policy.add_strategy(
ErrorCode::REQUEST_TIMEOUT,
RecoveryStrategy::RetryExponential {
attempts: 5,
initial_delay: Duration::from_millis(100),
max_delay: Duration::from_secs(10),
multiplier: 2.0,
}
);
// Get strategy for error code
let strategy = policy.get_strategy(&ErrorCode::REQUEST_TIMEOUT);Implementations§
Source§impl RecoveryPolicy
impl RecoveryPolicy
Sourcepub fn new(default_strategy: RecoveryStrategy) -> Self
pub fn new(default_strategy: RecoveryStrategy) -> Self
Create a new recovery policy.
Sourcepub fn add_strategy(
&mut self,
error_code: ErrorCode,
strategy: RecoveryStrategy,
)
pub fn add_strategy( &mut self, error_code: ErrorCode, strategy: RecoveryStrategy, )
Add a strategy for a specific error code.
Sourcepub fn get_strategy(&self, error_code: &ErrorCode) -> &RecoveryStrategy
pub fn get_strategy(&self, error_code: &ErrorCode) -> &RecoveryStrategy
Get strategy for an error code.
Trait Implementations§
Source§impl Clone for RecoveryPolicy
impl Clone for RecoveryPolicy
Source§impl Debug for RecoveryPolicy
impl Debug for RecoveryPolicy
Auto Trait Implementations§
impl Freeze for RecoveryPolicy
impl RefUnwindSafe for RecoveryPolicy
impl Send for RecoveryPolicy
impl Sync for RecoveryPolicy
impl Unpin for RecoveryPolicy
impl UnsafeUnpin for RecoveryPolicy
impl UnwindSafe for RecoveryPolicy
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more