diff options
author | Zach Reizner <zachr@google.com> | 2018-10-03 10:22:32 -0700 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2018-10-09 21:14:05 -0700 |
commit | 55a9e504beef368bd97e51ffd5a7fa6c034eb8ad (patch) | |
tree | 894d8685e2fdfa105ea35d1cb6cfceee06502c7a /sys_util/src/struct_util.rs | |
parent | 046df60760f3b0691f23c27a7f24a96c9afe8c05 (diff) | |
download | crosvm-55a9e504beef368bd97e51ffd5a7fa6c034eb8ad.tar crosvm-55a9e504beef368bd97e51ffd5a7fa6c034eb8ad.tar.gz crosvm-55a9e504beef368bd97e51ffd5a7fa6c034eb8ad.tar.bz2 crosvm-55a9e504beef368bd97e51ffd5a7fa6c034eb8ad.tar.lz crosvm-55a9e504beef368bd97e51ffd5a7fa6c034eb8ad.tar.xz crosvm-55a9e504beef368bd97e51ffd5a7fa6c034eb8ad.tar.zst crosvm-55a9e504beef368bd97e51ffd5a7fa6c034eb8ad.zip |
cargo fmt all source code
Now that cargo fmt has landed, run it over everything at once to bring rust source to the standard formatting. TEST=cargo test BUG=None Change-Id: Ic95a48725e5a40dcbd33ba6d5aef2bd01e91865b Reviewed-on: https://chromium-review.googlesource.com/1259287 Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com> Tested-by: Zach Reizner <zachr@chromium.org> Reviewed-by: Zach Reizner <zachr@chromium.org>
Diffstat (limited to 'sys_util/src/struct_util.rs')
-rw-r--r-- | sys_util/src/struct_util.rs | 70 |
1 files changed, 40 insertions, 30 deletions
diff --git a/sys_util/src/struct_util.rs b/sys_util/src/struct_util.rs index 05625b1..3d8def2 100644 --- a/sys_util/src/struct_util.rs +++ b/sys_util/src/struct_util.rs @@ -38,17 +38,19 @@ pub unsafe fn read_struct<T: Copy, F: Read>(f: &mut F, out: &mut T) -> Result<() pub unsafe fn read_struct_slice<T: Copy, F: Read>(f: &mut F, len: usize) -> Result<Vec<T>> { let mut out: Vec<T> = Vec::with_capacity(len); out.set_len(len); - let out_slice = std::slice::from_raw_parts_mut(out.as_ptr() as *mut T as *mut u8, - mem::size_of::<T>() * len); + let out_slice = std::slice::from_raw_parts_mut( + out.as_ptr() as *mut T as *mut u8, + mem::size_of::<T>() * len, + ); f.read_exact(out_slice).map_err(|_| Error::ReadStruct)?; Ok(out) } #[cfg(test)] mod test { + use super::*; use std::io::Cursor; use std::mem; - use super::*; #[derive(Clone, Copy, Debug, Default, PartialEq)] struct TestRead { @@ -70,8 +72,10 @@ mod test { }; let source = unsafe { // Don't worry it's a test - std::slice::from_raw_parts(&orig as *const _ as *const u8, - std::mem::size_of::<TestRead>()) + std::slice::from_raw_parts( + &orig as *const _ as *const u8, + std::mem::size_of::<TestRead>(), + ) }; assert_eq!(mem::size_of::<TestRead>(), mem::size_of_val(&source)); let mut tr: TestRead = Default::default(); @@ -92,8 +96,10 @@ mod test { }; let source = unsafe { // Don't worry it's a test - std::slice::from_raw_parts(&orig as *const _ as *const u8, - std::mem::size_of::<TestRead>() - 1) + std::slice::from_raw_parts( + &orig as *const _ as *const u8, + std::mem::size_of::<TestRead>() - 1, + ) }; let mut tr: TestRead = Default::default(); unsafe { @@ -103,31 +109,35 @@ mod test { #[test] fn struct_slice_read() { - let orig = vec![TestRead { - a: 0x7766554433221100, - b: 0x88, - c: 0x99, - d: 0xaa, - e: 0xbb, - }, - TestRead { - a: 0x7867564534231201, - b: 0x02, - c: 0x13, - d: 0x24, - e: 0x35, - }, - TestRead { - a: 0x7a69584736251403, - b: 0x04, - c: 0x15, - d: 0x26, - e: 0x37, - }]; + let orig = vec![ + TestRead { + a: 0x7766554433221100, + b: 0x88, + c: 0x99, + d: 0xaa, + e: 0xbb, + }, + TestRead { + a: 0x7867564534231201, + b: 0x02, + c: 0x13, + d: 0x24, + e: 0x35, + }, + TestRead { + a: 0x7a69584736251403, + b: 0x04, + c: 0x15, + d: 0x26, + e: 0x37, + }, + ]; let source = unsafe { // Don't worry it's a test - std::slice::from_raw_parts(orig.as_ptr() as *const u8, - std::mem::size_of::<TestRead>() * 3) + std::slice::from_raw_parts( + orig.as_ptr() as *const u8, + std::mem::size_of::<TestRead>() * 3, + ) }; let tr: Vec<TestRead> = unsafe { read_struct_slice(&mut Cursor::new(source), 3).unwrap() }; |