use anyhow::Result;
use serde::{Deserialize, Serialize};
use std::rc::Rc;
use std::time::Duration;
use thiserror::Error;
use super::nonblocking_help::{NoNonblockingHelp, NonblockingHelp};
use crate::impl_serializable_error;
#[derive(Error, Debug, Serialize, Deserialize)]
pub enum ConsoleError {
#[error("Unsupported: {0}")]
UnsupportedError(String),
#[error("{0}")]
GenericError(String),
}
impl_serializable_error!(ConsoleError);
pub trait ConsoleDevice {
fn console_read(&self, _buf: &mut [u8], _timeout: Duration) -> Result<usize> {
Err(ConsoleError::UnsupportedError("console_read() not implemented.".into()).into())
}
fn console_write(&self, _buf: &[u8]) -> Result<()> {
Err(ConsoleError::UnsupportedError("console_write() not implemented.".into()).into())
}
fn set_break(&self, _enable: bool) -> Result<()> {
Err(ConsoleError::GenericError("break unsupported".into()).into())
}
fn supports_nonblocking_read(&self) -> Result<bool> {
Ok(false)
}
fn register_nonblocking_read(
&self,
_registry: &mio::Registry,
_token: mio::Token,
) -> Result<()> {
unimplemented!();
}
fn nonblocking_help(&self) -> Result<Rc<dyn NonblockingHelp>> {
Ok(Rc::new(NoNonblockingHelp))
}
}