wasmer/lib/runtime-abi/src/vfs/device_file.rs

85 lines
2.1 KiB
Rust
Raw Normal View History

2019-03-21 15:55:23 +00:00
use crate::vfs::file_like::{FileLike, Metadata};
use failure::Error;
2019-03-26 02:43:52 +00:00
use std::io;
2019-03-28 18:41:45 +00:00
use std::io::{Seek, Write};
2019-03-21 15:55:23 +00:00
pub struct Stdin;
pub struct Stdout;
pub struct Stderr;
impl FileLike for Stdin {
2019-03-26 02:43:52 +00:00
fn metadata(&self) -> Result<Metadata, Error> {
unimplemented!()
2019-03-21 15:55:23 +00:00
}
2019-03-26 02:43:52 +00:00
fn write_file(&mut self, _buf: &[u8], _offset: usize) -> Result<usize, io::Error> {
2019-03-21 15:55:23 +00:00
unimplemented!()
}
2019-03-28 18:41:45 +00:00
fn read_file(&mut self, _buf: &mut [u8], _offset: usize) -> Result<usize, io::Error> {
unimplemented!()
}
fn set_file_len(&mut self, _len: usize) -> Result<(), failure::Error> {
panic!("Cannot set length of stdin");
}
2019-03-26 02:43:52 +00:00
}
2019-03-21 15:55:23 +00:00
2019-03-28 18:41:45 +00:00
impl io::Seek for Stdin {
fn seek(&mut self, _pos: io::SeekFrom) -> Result<u64, io::Error> {
2019-03-26 02:43:52 +00:00
unimplemented!()
2019-03-21 15:55:23 +00:00
}
2019-03-26 02:43:52 +00:00
}
2019-03-21 15:55:23 +00:00
2019-03-26 02:43:52 +00:00
impl FileLike for Stdout {
fn metadata(&self) -> Result<Metadata, failure::Error> {
unimplemented!()
}
fn write_file(&mut self, buf: &[u8], _offset: usize) -> Result<usize, io::Error> {
let stdout = io::stdout();
let mut handle = stdout.lock();
handle.write(buf)
}
2019-03-28 18:41:45 +00:00
fn read_file(&mut self, _buf: &mut [u8], _offset: usize) -> Result<usize, io::Error> {
unimplemented!()
}
fn set_file_len(&mut self, _len: usize) -> Result<(), failure::Error> {
panic!("Cannot set length of stdout");
}
2019-03-26 02:43:52 +00:00
}
2019-03-28 18:41:45 +00:00
impl io::Seek for Stdout {
fn seek(&mut self, _pos: io::SeekFrom) -> Result<u64, io::Error> {
2019-03-26 02:43:52 +00:00
unimplemented!()
}
}
impl FileLike for Stderr {
fn metadata(&self) -> Result<Metadata, failure::Error> {
unimplemented!()
}
fn write_file(&mut self, buf: &[u8], _offset: usize) -> Result<usize, io::Error> {
let stderr = io::stderr();
let mut handle = stderr.lock();
handle.write(buf)
}
2019-03-28 18:41:45 +00:00
fn read_file(&mut self, _buf: &mut [u8], _offset: usize) -> Result<usize, io::Error> {
unimplemented!()
}
fn set_file_len(&mut self, _len: usize) -> Result<(), failure::Error> {
panic!("Cannot set length of stderr");
}
2019-03-26 02:43:52 +00:00
}
2019-03-28 18:41:45 +00:00
impl io::Seek for Stderr {
fn seek(&mut self, _pos: io::SeekFrom) -> Result<u64, io::Error> {
2019-03-21 15:55:23 +00:00
unimplemented!()
}
}