use super::SerialIo;
use mesh::MeshPayload;
use pal_async::driver::Driver;
use vm_resource::CanResolveTo;
use vm_resource::Resource;
use vm_resource::ResourceId;
use vm_resource::kind::SerialBackendHandle;
impl CanResolveTo<ResolvedSerialBackend> for SerialBackendHandle {
type Input<'a> = ResolveSerialBackendParams<'a>;
}
pub struct ResolveSerialBackendParams<'a> {
pub driver: Box<dyn Driver>,
#[doc(hidden)]
pub _async_trait_workaround: &'a (),
}
pub struct ResolvedSerialBackend(pub Box<dyn SerialBackend>);
impl<T: 'static + SerialBackend> From<T> for ResolvedSerialBackend {
fn from(value: T) -> Self {
Self(Box::new(value))
}
}
pub trait SerialBackend: Send {
fn into_resource(self: Box<Self>) -> Resource<SerialBackendHandle>;
fn as_io(&self) -> &dyn SerialIo;
fn as_io_mut(&mut self) -> &mut dyn SerialIo;
fn into_io(self: Box<Self>) -> Box<dyn SerialIo>;
}
impl<T: 'static + SerialIo + Into<Resource<SerialBackendHandle>>> SerialBackend for T {
fn into_resource(self: Box<Self>) -> Resource<SerialBackendHandle> {
(*self).into()
}
fn as_io(&self) -> &dyn SerialIo {
self
}
fn as_io_mut(&mut self) -> &mut dyn SerialIo {
self
}
fn into_io(self: Box<Self>) -> Box<dyn SerialIo> {
self
}
}
#[derive(MeshPayload)]
pub struct DisconnectedSerialBackendHandle;
impl ResourceId<SerialBackendHandle> for DisconnectedSerialBackendHandle {
const ID: &'static str = "disconnected";
}