use scpi::prelude::*; use scpi::Context; use scpi::error::Result; use arrayvec::{ArrayVec}; pub trait MqttScpiTranslator { fn run_with_mqtt(&mut self, s: &[u8], response: &mut FMT) -> Result<()>; } impl<'a, T: Device> MqttScpiTranslator for Context<'a, T> { fn run_with_mqtt(&mut self, s: &[u8], response: &mut FMT) -> Result<()> where FMT: Formatter, { let mut array_vec = ArrayVec::<[u8; 1024]>::new(); for i in s.into_iter() { if *i == b'/' { array_vec.try_push(b'/') .map_err(|_| ErrorCode::OutOfMemory)?; } else { array_vec.try_push(*i) .map_err(|_| ErrorCode::OutOfMemory)?; } } self.run(array_vec.as_slice(), response) } }