io_tether/
config.rs

1//! Contains options for fine-tuning Tether behavior
2
3/// Tether configuration definition
4#[non_exhaustive]
5#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
6pub struct Config {
7    /// Determines the behavior in the event an error occurs when attempting to write data.
8    ///
9    /// + true: The original data will be written once the connection is re-established
10    /// + false: The data will be cleared in the event of an error
11    ///
12    /// Default: true
13    ///
14    /// # Rationale
15    ///
16    /// For some applications, the data written to an I/O object is time-sensitive, and it is
17    /// preferable to drop data which cannot be delivered in short order, rather than send it with
18    /// some unknown delay
19    pub keep_data_on_failed_write: bool,
20    /// Determines the response of the I/O object in the event the [`Resolver`](crate::Resolver)
21    /// elects *not* to reconnect. See [`ErrorPropagation`] for more details
22    ///
23    /// Default: [`ErrorPropagation::IoOperations`]
24    pub error_propagation_on_no_retry: ErrorPropagation,
25}
26
27impl Config {
28    pub fn set_keep_data_on_failed_write(mut self, value: bool) -> Self {
29        self.keep_data_on_failed_write = value;
30        self
31    }
32
33    pub fn set_error_propagation_on_no_retry(mut self, value: ErrorPropagation) -> Self {
34        self.error_propagation_on_no_retry = value;
35        self
36    }
37}
38
39impl Default for Config {
40    fn default() -> Self {
41        Self {
42            keep_data_on_failed_write: true,
43            error_propagation_on_no_retry: ErrorPropagation::IoOperations,
44        }
45    }
46}
47
48/// Determines the return type of the callsites when the Resolver returns `false` (indicating a
49/// retry should not be attempted).
50#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
51pub enum ErrorPropagation {
52    /// No error will be produced
53    None,
54    /// The latest error will be propagated *only if* it stemmed from an underlying I/O error, but
55    /// not if it occurred as a result of previous failures to reconnect.
56    IoOperations,
57    /// The latest error will be returned
58    All,
59}