Remove Any Trait of File
This commit is contained in:
parent
946b37a237
commit
d6056ef07c
3 changed files with 1 additions and 16 deletions
|
@ -2,19 +2,9 @@ mod pipe;
|
||||||
mod stdio;
|
mod stdio;
|
||||||
|
|
||||||
use crate::mm::UserBuffer;
|
use crate::mm::UserBuffer;
|
||||||
use core::any::Any;
|
pub trait File : Send + Sync {
|
||||||
|
|
||||||
pub trait File : Any + Send + Sync {
|
|
||||||
fn read(&self, buf: UserBuffer) -> usize;
|
fn read(&self, buf: UserBuffer) -> usize;
|
||||||
fn write(&self, buf: UserBuffer) -> usize;
|
fn write(&self, buf: UserBuffer) -> usize;
|
||||||
fn as_any_ref(&self) -> &dyn Any;
|
|
||||||
}
|
|
||||||
|
|
||||||
impl dyn File {
|
|
||||||
#[allow(unused)]
|
|
||||||
pub fn downcast_ref<T: File>(&self) -> Option<&T> {
|
|
||||||
self.as_any_ref().downcast_ref::<T>()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub use pipe::{Pipe, make_pipe};
|
pub use pipe::{Pipe, make_pipe};
|
||||||
|
|
|
@ -5,7 +5,6 @@ use crate::mm::{
|
||||||
UserBuffer,
|
UserBuffer,
|
||||||
};
|
};
|
||||||
use crate::task::suspend_current_and_run_next;
|
use crate::task::suspend_current_and_run_next;
|
||||||
use core::any::Any;
|
|
||||||
|
|
||||||
pub struct Pipe {
|
pub struct Pipe {
|
||||||
readable: bool,
|
readable: bool,
|
||||||
|
@ -163,5 +162,4 @@ impl File for Pipe {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fn as_any_ref(&self) -> &dyn Any { self }
|
|
||||||
}
|
}
|
|
@ -2,7 +2,6 @@ use super::File;
|
||||||
use crate::mm::{UserBuffer};
|
use crate::mm::{UserBuffer};
|
||||||
use crate::sbi::console_getchar;
|
use crate::sbi::console_getchar;
|
||||||
use crate::task::suspend_current_and_run_next;
|
use crate::task::suspend_current_and_run_next;
|
||||||
use core::any::Any;
|
|
||||||
|
|
||||||
pub struct Stdin;
|
pub struct Stdin;
|
||||||
|
|
||||||
|
@ -29,7 +28,6 @@ impl File for Stdin {
|
||||||
fn write(&self, _user_buf: UserBuffer) -> usize {
|
fn write(&self, _user_buf: UserBuffer) -> usize {
|
||||||
panic!("Cannot write to stdin!");
|
panic!("Cannot write to stdin!");
|
||||||
}
|
}
|
||||||
fn as_any_ref(&self) -> &dyn Any { self }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl File for Stdout {
|
impl File for Stdout {
|
||||||
|
@ -42,5 +40,4 @@ impl File for Stdout {
|
||||||
}
|
}
|
||||||
user_buf.len()
|
user_buf.len()
|
||||||
}
|
}
|
||||||
fn as_any_ref(&self) -> &dyn Any { self }
|
|
||||||
}
|
}
|
Loading…
Add table
Add a link
Reference in a new issue