@@ -75,13 +75,15 @@ impl Default for Block {
7575
7676/// A block device - a device which can read and write blocks (or
7777/// sectors). Only supports devices which are <= 2 TiB in size.
78+ #[ allow( async_fn_in_trait) ]
79+ #[ maybe_async:: maybe_async( AFIT ) ]
7880pub trait BlockDevice {
7981 /// The errors that the `BlockDevice` can return. Must be debug formattable.
8082 type Error : core:: fmt:: Debug ;
8183 /// Read one or more blocks, starting at the given block index.
82- fn read ( & self , blocks : & mut [ Block ] , start_block_idx : BlockIdx ) -> Result < ( ) , Self :: Error > ;
84+ async fn read ( & self , blocks : & mut [ Block ] , start_block_idx : BlockIdx ) -> Result < ( ) , Self :: Error > ;
8385 /// Write one or more blocks, starting at the given block index.
84- fn write ( & self , blocks : & [ Block ] , start_block_idx : BlockIdx ) -> Result < ( ) , Self :: Error > ;
86+ async fn write ( & self , blocks : & [ Block ] , start_block_idx : BlockIdx ) -> Result < ( ) , Self :: Error > ;
8587 /// Determine how many blocks this device can hold.
8688 fn num_blocks ( & self ) -> Result < BlockCount , Self :: Error > ;
8789}
@@ -110,31 +112,34 @@ where
110112 }
111113
112114 /// Read a block, and return a reference to it.
113- pub fn read ( & mut self , block_idx : BlockIdx ) -> Result < & Block , D :: Error > {
115+ #[ maybe_async:: maybe_async]
116+ pub async fn read ( & mut self , block_idx : BlockIdx ) -> Result < & Block , D :: Error > {
114117 if self . block_idx != Some ( block_idx) {
115118 self . block_idx = None ;
116- self . block_device . read ( & mut self . block , block_idx) ?;
119+ self . block_device . read ( & mut self . block , block_idx) . await ?;
117120 self . block_idx = Some ( block_idx) ;
118121 }
119122 Ok ( & self . block [ 0 ] )
120123 }
121124
122125 /// Read a block, and return a reference to it.
123- pub fn read_mut ( & mut self , block_idx : BlockIdx ) -> Result < & mut Block , D :: Error > {
126+ #[ maybe_async:: maybe_async]
127+ pub async fn read_mut ( & mut self , block_idx : BlockIdx ) -> Result < & mut Block , D :: Error > {
124128 if self . block_idx != Some ( block_idx) {
125129 self . block_idx = None ;
126- self . block_device . read ( & mut self . block , block_idx) ?;
130+ self . block_device . read ( & mut self . block , block_idx) . await ?;
127131 self . block_idx = Some ( block_idx) ;
128132 }
129133 Ok ( & mut self . block [ 0 ] )
130134 }
131135
132136 /// Write back a block you read with [`Self::read_mut`] and then modified.
133- pub fn write_back ( & mut self ) -> Result < ( ) , D :: Error > {
137+ #[ maybe_async:: maybe_async]
138+ pub async fn write_back ( & mut self ) -> Result < ( ) , D :: Error > {
134139 self . block_device . write (
135140 & self . block ,
136141 self . block_idx . expect ( "write_back with no read" ) ,
137- )
142+ ) . await
138143 }
139144
140145 /// Access a blank sector
0 commit comments