1
- use crate :: { dap, screen} ;
2
- use core:: fmt:: Write as _;
1
+ use crate :: dap;
3
2
4
3
#[ derive( Clone ) ]
5
4
pub struct DiskAccess {
@@ -10,7 +9,7 @@ pub struct DiskAccess {
10
9
11
10
impl Read for DiskAccess {
12
11
fn read_exact ( & mut self , len : usize ) -> & [ u8 ] {
13
- static mut TMP_BUF : AlignedBuffer < 512 > = AlignedBuffer {
12
+ static mut TMP_BUF : AlignedArrayBuffer < 512 > = AlignedArrayBuffer {
14
13
buffer : [ 0 ; 512 ] ,
15
14
limit : 512 ,
16
15
} ;
@@ -22,7 +21,7 @@ impl Read for DiskAccess {
22
21
& buf. buffer [ ..len]
23
22
}
24
23
25
- fn read_exact_into ( & mut self , buf : & mut dyn AlignedSlice ) {
24
+ fn read_exact_into ( & mut self , buf : & mut dyn AlignedBuffer ) {
26
25
let buf = buf. slice_mut ( ) ;
27
26
assert_eq ! ( buf. len( ) % 512 , 0 ) ;
28
27
@@ -77,7 +76,7 @@ impl Seek for DiskAccess {
77
76
78
77
pub trait Read {
79
78
fn read_exact ( & mut self , len : usize ) -> & [ u8 ] ;
80
- fn read_exact_into ( & mut self , buf : & mut dyn AlignedSlice ) ;
79
+ fn read_exact_into ( & mut self , buf : & mut dyn AlignedBuffer ) ;
81
80
}
82
81
83
82
#[ derive( Debug , Clone , Copy , PartialEq , Eq ) ]
@@ -91,21 +90,26 @@ pub trait Seek {
91
90
}
92
91
93
92
#[ repr( align( 2 ) ) ]
94
- pub struct AlignedBuffer < const LEN : usize > {
93
+ pub struct AlignedArrayBuffer < const LEN : usize > {
95
94
pub buffer : [ u8 ; LEN ] ,
96
95
pub limit : usize ,
97
96
}
98
97
99
- pub trait AlignedSlice {
98
+ pub trait AlignedBuffer {
100
99
fn slice ( & self ) -> & [ u8 ] ;
101
100
fn slice_mut ( & mut self ) -> & mut [ u8 ] ;
101
+ fn set_limit ( & mut self , limit : usize ) ;
102
102
}
103
103
104
- impl < const LEN : usize > AlignedSlice for AlignedBuffer < LEN > {
104
+ impl < const LEN : usize > AlignedBuffer for AlignedArrayBuffer < LEN > {
105
105
fn slice ( & self ) -> & [ u8 ] {
106
106
& self . buffer [ ..self . limit ]
107
107
}
108
108
fn slice_mut ( & mut self ) -> & mut [ u8 ] {
109
109
& mut self . buffer [ ..self . limit ]
110
110
}
111
+ fn set_limit ( & mut self , limit : usize ) {
112
+ assert ! ( limit <= LEN ) ;
113
+ self . limit = limit;
114
+ }
111
115
}
0 commit comments