1- use crate :: { dap, screen} ;
2- use core:: fmt:: Write as _;
1+ use crate :: dap;
32
43#[ derive( Clone ) ]
54pub struct DiskAccess {
@@ -10,7 +9,7 @@ pub struct DiskAccess {
109
1110impl Read for DiskAccess {
1211 fn read_exact ( & mut self , len : usize ) -> & [ u8 ] {
13- static mut TMP_BUF : AlignedBuffer < 512 > = AlignedBuffer {
12+ static mut TMP_BUF : AlignedArrayBuffer < 512 > = AlignedArrayBuffer {
1413 buffer : [ 0 ; 512 ] ,
1514 limit : 512 ,
1615 } ;
@@ -22,7 +21,7 @@ impl Read for DiskAccess {
2221 & buf. buffer [ ..len]
2322 }
2423
25- fn read_exact_into ( & mut self , buf : & mut dyn AlignedSlice ) {
24+ fn read_exact_into ( & mut self , buf : & mut dyn AlignedBuffer ) {
2625 let buf = buf. slice_mut ( ) ;
2726 assert_eq ! ( buf. len( ) % 512 , 0 ) ;
2827
@@ -77,7 +76,7 @@ impl Seek for DiskAccess {
7776
7877pub trait Read {
7978 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 ) ;
8180}
8281
8382#[ derive( Debug , Clone , Copy , PartialEq , Eq ) ]
@@ -91,21 +90,26 @@ pub trait Seek {
9190}
9291
9392#[ repr( align( 2 ) ) ]
94- pub struct AlignedBuffer < const LEN : usize > {
93+ pub struct AlignedArrayBuffer < const LEN : usize > {
9594 pub buffer : [ u8 ; LEN ] ,
9695 pub limit : usize ,
9796}
9897
99- pub trait AlignedSlice {
98+ pub trait AlignedBuffer {
10099 fn slice ( & self ) -> & [ u8 ] ;
101100 fn slice_mut ( & mut self ) -> & mut [ u8 ] ;
101+ fn set_limit ( & mut self , limit : usize ) ;
102102}
103103
104- impl < const LEN : usize > AlignedSlice for AlignedBuffer < LEN > {
104+ impl < const LEN : usize > AlignedBuffer for AlignedArrayBuffer < LEN > {
105105 fn slice ( & self ) -> & [ u8 ] {
106106 & self . buffer [ ..self . limit ]
107107 }
108108 fn slice_mut ( & mut self ) -> & mut [ u8 ] {
109109 & mut self . buffer [ ..self . limit ]
110110 }
111+ fn set_limit ( & mut self , limit : usize ) {
112+ assert ! ( limit <= LEN ) ;
113+ self . limit = limit;
114+ }
111115}
0 commit comments