@@ -18,13 +18,16 @@ pub enum Error {
1818pub type Result < T > = std:: result:: Result < T , Error > ;
1919
2020/// 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.
2321///
2422/// # Arguments
2523///
2624/// * `f` - The input to read from. Often this is a file.
2725/// * `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.
2831pub unsafe fn read_struct < T : Copy , F : Read > ( f : & mut F , out : & mut T ) -> Result < ( ) > {
2932 let out_slice = std:: slice:: from_raw_parts_mut ( out as * mut T as * mut u8 , mem:: size_of :: < T > ( ) ) ;
3033 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<()
3336
3437/// Reads an array of structs from an input buffer. Returns a Vec of structs initialized with data
3538/// 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.
3839///
3940/// # Arguments
4041///
4142/// * `f` - The input to read from. Often this is a file.
4243/// * `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.
4349#[ cfg( feature = "elf" ) ]
4450pub unsafe fn read_struct_slice < T : Copy , F : Read > ( f : & mut F , len : usize ) -> Result < Vec < T > > {
4551 let mut out: Vec < T > = Vec :: with_capacity ( len) ;
0 commit comments