use crate::fax::negotiate::DataRate; #[derive(Debug, Clone)] pub struct SpeedFallback { rates: Vec, current_index: usize, } impl Default for SpeedFallback { fn default() -> Self { Self { rates: vec![ DataRate::V17_14400, DataRate::V17_12000, DataRate::V29_9600, DataRate::V29_7200, DataRate::V27ter4800, ], current_index: 0, } } } impl SpeedFallback { pub fn new() -> Self { Self::default() } pub fn current_rate(&self) -> DataRate { self.rates[self.current_index] } pub fn lower_speed(&mut self) -> Option { if self.current_index + 1 < self.rates.len() { self.current_index += 1; Some(self.rates[self.current_index]) } else { None } } pub fn reset(&mut self) { self.current_index = 0; } pub fn is_min_speed(&self) -> bool { self.current_index == self.rates.len() - 1 } pub fn set_initial_rate(&mut self, rate: DataRate) { for (i, r) in self.rates.iter().enumerate() { if *r == rate { self.current_index = i; return; } } self.current_index = 0; } }