-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathio.rs
More file actions
48 lines (38 loc) · 1.01 KB
/
io.rs
File metadata and controls
48 lines (38 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
use alloc::boxed::Box;
use dyn_clone::{DynClone, clone_trait_object};
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
pub struct FileDescriptorId(u32);
impl FileDescriptorId {
pub fn new(id: u32) -> Self {
Self(id)
}
pub fn id(&self) -> u32 {
self.0
}
}
#[derive(Debug)]
pub enum IOError {
Unsupported,
NotFound,
}
pub type IOResult<T> = Result<T, IOError>;
pub type FileSize = u64;
#[derive(Eq, PartialEq)]
pub enum FileType {
File,
Directory,
}
pub struct FileStat {
pub size: FileSize,
pub r#type: FileType,
}
#[async_trait::async_trait]
pub trait File: Send + DynClone {
async fn read(&mut self, buf: &mut [u8]) -> IOResult<usize>;
async fn write(&mut self, buf: &[u8]) -> IOResult<usize>;
async fn seek(&mut self, pos: FileSize) -> IOResult<()>;
async fn tell(&self) -> IOResult<FileSize>;
async fn set_len(&mut self, len: FileSize) -> IOResult<()>;
async fn metadata(&self) -> IOResult<FileStat>;
}
clone_trait_object!(File);