1
+ use crate :: preview2:: bindings:: filesystem:: types:: Descriptor ;
1
2
use crate :: preview2:: {
2
3
AbortOnDropJoinHandle , HostOutputStream , OutputStreamError , StreamRuntimeError , StreamState ,
3
4
Table , TableError ,
@@ -6,6 +7,7 @@ use anyhow::anyhow;
6
7
use bytes:: { Bytes , BytesMut } ;
7
8
use futures:: future:: { maybe_done, MaybeDone } ;
8
9
use std:: sync:: Arc ;
10
+ use wasmtime:: component:: Resource ;
9
11
10
12
bitflags:: bitflags! {
11
13
#[ derive( Copy , Clone , Debug , PartialEq , Eq ) ]
@@ -44,42 +46,42 @@ impl File {
44
46
}
45
47
}
46
48
pub ( crate ) trait TableFsExt {
47
- fn push_file ( & mut self , file : File ) -> Result < u32 , TableError > ;
48
- fn delete_file ( & mut self , fd : u32 ) -> Result < File , TableError > ;
49
- fn is_file ( & self , fd : u32 ) -> bool ;
50
- fn get_file ( & self , fd : u32 ) -> Result < & File , TableError > ;
49
+ fn push_file ( & mut self , file : File ) -> Result < Resource < Descriptor > , TableError > ;
50
+ fn delete_file ( & mut self , fd : Resource < Descriptor > ) -> Result < File , TableError > ;
51
+ fn is_file ( & self , fd : & Resource < Descriptor > ) -> bool ;
52
+ fn get_file ( & self , fd : & Resource < Descriptor > ) -> Result < & File , TableError > ;
51
53
52
- fn push_dir ( & mut self , dir : Dir ) -> Result < u32 , TableError > ;
53
- fn delete_dir ( & mut self , fd : u32 ) -> Result < Dir , TableError > ;
54
- fn is_dir ( & self , fd : u32 ) -> bool ;
55
- fn get_dir ( & self , fd : u32 ) -> Result < & Dir , TableError > ;
54
+ fn push_dir ( & mut self , dir : Dir ) -> Result < Resource < Descriptor > , TableError > ;
55
+ fn delete_dir ( & mut self , fd : Resource < Descriptor > ) -> Result < Dir , TableError > ;
56
+ fn is_dir ( & self , fd : & Resource < Descriptor > ) -> bool ;
57
+ fn get_dir ( & self , fd : & Resource < Descriptor > ) -> Result < & Dir , TableError > ;
56
58
}
57
59
58
60
impl TableFsExt for Table {
59
- fn push_file ( & mut self , file : File ) -> Result < u32 , TableError > {
60
- self . push ( Box :: new ( file) )
61
+ fn push_file ( & mut self , file : File ) -> Result < Resource < Descriptor > , TableError > {
62
+ Ok ( Resource :: new_own ( self . push ( Box :: new ( file) ) ? ) )
61
63
}
62
- fn delete_file ( & mut self , fd : u32 ) -> Result < File , TableError > {
63
- self . delete ( fd)
64
+ fn delete_file ( & mut self , fd : Resource < Descriptor > ) -> Result < File , TableError > {
65
+ self . delete ( fd. rep ( ) )
64
66
}
65
- fn is_file ( & self , fd : u32 ) -> bool {
66
- self . is :: < File > ( fd)
67
+ fn is_file ( & self , fd : & Resource < Descriptor > ) -> bool {
68
+ self . is :: < File > ( fd. rep ( ) )
67
69
}
68
- fn get_file ( & self , fd : u32 ) -> Result < & File , TableError > {
69
- self . get ( fd)
70
+ fn get_file ( & self , fd : & Resource < Descriptor > ) -> Result < & File , TableError > {
71
+ self . get ( fd. rep ( ) )
70
72
}
71
73
72
- fn push_dir ( & mut self , dir : Dir ) -> Result < u32 , TableError > {
73
- self . push ( Box :: new ( dir) )
74
+ fn push_dir ( & mut self , dir : Dir ) -> Result < Resource < Descriptor > , TableError > {
75
+ Ok ( Resource :: new_own ( self . push ( Box :: new ( dir) ) ? ) )
74
76
}
75
- fn delete_dir ( & mut self , fd : u32 ) -> Result < Dir , TableError > {
76
- self . delete ( fd)
77
+ fn delete_dir ( & mut self , fd : Resource < Descriptor > ) -> Result < Dir , TableError > {
78
+ self . delete ( fd. rep ( ) )
77
79
}
78
- fn is_dir ( & self , fd : u32 ) -> bool {
79
- self . is :: < Dir > ( fd)
80
+ fn is_dir ( & self , fd : & Resource < Descriptor > ) -> bool {
81
+ self . is :: < Dir > ( fd. rep ( ) )
80
82
}
81
- fn get_dir ( & self , fd : u32 ) -> Result < & Dir , TableError > {
82
- self . get ( fd)
83
+ fn get_dir ( & self , fd : & Resource < Descriptor > ) -> Result < & Dir , TableError > {
84
+ self . get ( fd. rep ( ) )
83
85
}
84
86
}
85
87
0 commit comments