use anyhow::Result;
use super::device::NetworkDevice;
pub trait Configurable {
type SessionType: Configurable + NetworkDevice;
fn enter_config(&mut self) -> Result<ConfigurationMode<Self::SessionType>>;
fn exit(&mut self) -> Result<()>;
}
pub struct ConfigurationMode<'a, T: Configurable + NetworkDevice> {
session: &'a mut T,
}
impl<'a, T: Configurable + NetworkDevice> ConfigurationMode<'a, T> {
pub fn new(session: &'a mut T) -> Self {
ConfigurationMode { session }
}
pub fn execute(&mut self, command: &str) -> Result<String> {
self.session.execute(command)
}
}
impl<T: Configurable + NetworkDevice> Drop for ConfigurationMode<'_, T> {
fn drop(&mut self) {
let _ = self.session.exit();
}
}