SzResultExt

Trait SzResultExt 

Source
pub trait SzResultExt<T> {
    // Required methods
    fn or_retry<F>(self, f: F) -> SzResult<T>
       where F: FnOnce(SzError) -> SzResult<T>;
    fn map_retryable<F>(self, f: F) -> SzResult<T>
       where F: FnOnce(SzError) -> SzResult<T>;
    fn filter_retryable(self) -> Result<Option<T>, SzError>;
    fn is_retryable_error(&self) -> bool;
    fn is_unrecoverable_error(&self) -> bool;
    fn is_bad_input_error(&self) -> bool;
}
Expand description

Extension trait for SzResult<T> providing error classification helpers.

These methods let you handle retryable errors inline without explicit match arms. They operate on SzResult (i.e., Result<T, SzError>) returned by SDK calls.

§Examples

use sz_rust_sdk::prelude::*;

engine.add_record("TEST", "1", r#"{"NAME_FULL":"Test"}"#, None)
    .or_retry(|e| {
        eprintln!("Retrying due to: {e}");
        engine.add_record("TEST", "1", r#"{"NAME_FULL":"Test"}"#, None)
    })

Required Methods§

Source

fn or_retry<F>(self, f: F) -> SzResult<T>
where F: FnOnce(SzError) -> SzResult<T>,

If the error is retryable, call the provided closure; otherwise propagate the error.

§Examples
use sz_rust_sdk::prelude::*;

engine.add_record("TEST", "1", "{}", None)
    .or_retry(|e| {
        eprintln!("Retrying: {e}");
        engine.add_record("TEST", "1", "{}", None)
    })
Source

fn map_retryable<F>(self, f: F) -> SzResult<T>
where F: FnOnce(SzError) -> SzResult<T>,

Maps retryable errors using the provided function, propagates non-retryable errors.

§Examples
use sz_rust_sdk::prelude::*;

engine.add_record("TEST", "1", "{}", None)
    .map_retryable(|e| {
        eprintln!("Will retry: {e}");
        engine.add_record("TEST", "1", "{}", None)
    })
Source

fn filter_retryable(self) -> Result<Option<T>, SzError>

Returns Ok(None) for retryable errors, Err for non-retryable errors.

Useful for filtering retryable errors out of a processing loop.

§Examples
use sz_rust_sdk::prelude::*;

match engine.add_record("TEST", "1", "{}", None).filter_retryable() {
    Ok(Some(info)) => println!("Success: {info}"),
    Ok(None) => println!("Retryable error, will retry"),
    Err(e) => println!("Fatal error: {e}"),
}
Source

fn is_retryable_error(&self) -> bool

Returns true if the result is an error and that error is retryable

Source

fn is_unrecoverable_error(&self) -> bool

Returns true if the result is an error and that error is unrecoverable

Source

fn is_bad_input_error(&self) -> bool

Returns true if the result is an error and that error is bad input

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<T> SzResultExt<T> for SzResult<T>