@@ -47,11 +47,14 @@ where
4747 ///
4848 /// The file must have been opened with read and write permissions.
4949 ///
50+ /// `magic` is the expected prefixed bytes of the file. If this does not match, an error will be
51+ /// returned.
52+ ///
5053 /// [`File`]: std::fs::File
5154 pub fn new ( magic : & ' a [ u8 ] , mut db_file : File ) -> Result < Self , FileError > {
5255 db_file. rewind ( ) ?;
5356
54- let mut magic_buf = Vec :: from_iter ( ( 0 .. ) . take ( magic. len ( ) ) ) ;
57+ let mut magic_buf = vec ! [ 0_u8 ; magic. len( ) ] ;
5558 db_file. read_exact ( magic_buf. as_mut ( ) ) ?;
5659
5760 if magic_buf != magic {
7174 /// Creates or loads a store from `db_path`.
7275 ///
7376 /// If no file exists there, it will be created.
77+ ///
78+ /// Refer to [`new`] for documentation on the `magic` input.
79+ ///
80+ /// [`new`]: Self::new
7481 pub fn new_from_path < P > ( magic : & ' a [ u8 ] , db_path : P ) -> Result < Self , FileError >
7582 where
7683 P : AsRef < Path > ,
@@ -170,46 +177,7 @@ mod test {
170177 const TEST_MAGIC_BYTES : [ u8 ; TEST_MAGIC_BYTES_LEN ] =
171178 [ 98 , 100 , 107 , 102 , 115 , 49 , 49 , 49 , 49 , 49 , 49 , 49 ] ;
172179
173- #[ derive(
174- Debug ,
175- Clone ,
176- Copy ,
177- PartialOrd ,
178- Ord ,
179- PartialEq ,
180- Eq ,
181- Hash ,
182- serde:: Serialize ,
183- serde:: Deserialize ,
184- ) ]
185- enum TestKeychain {
186- External ,
187- Internal ,
188- }
189-
190- impl core:: fmt:: Display for TestKeychain {
191- fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
192- match self {
193- Self :: External => write ! ( f, "external" ) ,
194- Self :: Internal => write ! ( f, "internal" ) ,
195- }
196- }
197- }
198-
199- #[ derive( Debug , Default , serde:: Serialize , serde:: Deserialize ) ]
200- struct TestChangeSet {
201- pub changes : Vec < String > ,
202- }
203-
204- impl Append for TestChangeSet {
205- fn append ( & mut self , mut other : Self ) {
206- self . changes . append ( & mut other. changes )
207- }
208-
209- fn is_empty ( & self ) -> bool {
210- self . changes . is_empty ( )
211- }
212- }
180+ type TestChangeSet = Vec < String > ;
213181
214182 #[ derive( Debug ) ]
215183 struct TestTracker ;
@@ -248,9 +216,7 @@ mod test {
248216 let mut data = [ 255_u8 ; 2000 ] ;
249217 data[ ..TEST_MAGIC_BYTES_LEN ] . copy_from_slice ( & TEST_MAGIC_BYTES ) ;
250218
251- let changeset = TestChangeSet {
252- changes : vec ! [ "one" . into( ) , "two" . into( ) , "three!" . into( ) ] ,
253- } ;
219+ let changeset = vec ! [ "one" . into( ) , "two" . into( ) , "three!" . into( ) ] ;
254220
255221 let mut file = NamedTempFile :: new ( ) . unwrap ( ) ;
256222 file. write_all ( & data) . expect ( "should write" ) ;
0 commit comments