@@ -18,13 +18,16 @@ pub enum Error {
18
18
pub type Result < T > = std:: result:: Result < T , Error > ;
19
19
20
20
/// Reads a struct from an input buffer.
21
- /// This is unsafe because the struct is initialized to unverified data read from the input.
22
- /// `read_struct` should only be called to fill plain old data structs. It is not endian safe.
23
21
///
24
22
/// # Arguments
25
23
///
26
24
/// * `f` - The input to read from. Often this is a file.
27
25
/// * `out` - The struct to fill with data read from `f`.
26
+ ///
27
+ /// # Safety
28
+ ///
29
+ /// This is unsafe because the struct is initialized to unverified data read from the input.
30
+ /// `read_struct` should only be called to fill plain data structs. It is not endian safe.
28
31
pub unsafe fn read_struct < T : Copy , F : Read > ( f : & mut F , out : & mut T ) -> Result < ( ) > {
29
32
let out_slice = std:: slice:: from_raw_parts_mut ( out as * mut T as * mut u8 , mem:: size_of :: < T > ( ) ) ;
30
33
f. read_exact ( out_slice) . map_err ( |_| Error :: ReadStruct ) ?;
@@ -33,13 +36,16 @@ pub unsafe fn read_struct<T: Copy, F: Read>(f: &mut F, out: &mut T) -> Result<()
33
36
34
37
/// Reads an array of structs from an input buffer. Returns a Vec of structs initialized with data
35
38
/// from the specified input.
36
- /// This is unsafe because the structs are initialized to unverified data read from the input.
37
- /// `read_struct_slice` should only be called for plain old data structs. It is not endian safe.
38
39
///
39
40
/// # Arguments
40
41
///
41
42
/// * `f` - The input to read from. Often this is a file.
42
43
/// * `len` - The number of structs to fill with data read from `f`.
44
+ ///
45
+ /// # Safety
46
+ ///
47
+ /// This is unsafe because the struct is initialized to unverified data read from the input.
48
+ /// `read_struct_slice` should only be called to fill plain data structs. It is not endian safe.
43
49
#[ cfg( feature = "elf" ) ]
44
50
pub unsafe fn read_struct_slice < T : Copy , F : Read > ( f : & mut F , len : usize ) -> Result < Vec < T > > {
45
51
let mut out: Vec < T > = Vec :: with_capacity ( len) ;
0 commit comments