diff options
author | Chelsea Holland Komlo <me@chelseakomlo.com> | 2017-10-26 09:50:50 -0400 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2017-10-27 10:02:08 -0400 |
commit | 6be75bd61d72636a1c23b6fd9866d33a35433a73 (patch) | |
tree | e126a94f3baf863f49f5ff0addcc952ce20e3018 /src/rust/tor_allocate | |
parent | 90daad999e78c8ec8239e63ea03df6b3b2e364b6 (diff) | |
download | tor-6be75bd61d72636a1c23b6fd9866d33a35433a73.tar.gz tor-6be75bd61d72636a1c23b6fd9866d33a35433a73.zip |
cargo fmt; fix line length warnings
Diffstat (limited to 'src/rust/tor_allocate')
-rw-r--r-- | src/rust/tor_allocate/tor_allocate.rs | 18 |
1 files changed, 8 insertions, 10 deletions
diff --git a/src/rust/tor_allocate/tor_allocate.rs b/src/rust/tor_allocate/tor_allocate.rs index 03ed2499c7..663600ec5c 100644 --- a/src/rust/tor_allocate/tor_allocate.rs +++ b/src/rust/tor_allocate/tor_allocate.rs @@ -3,13 +3,13 @@ use std::{ptr, slice, mem}; #[cfg(not(test))] extern "C" { - fn tor_malloc_ ( size: usize) -> *mut c_void; + fn tor_malloc_(size: usize) -> *mut c_void; } // Defined only for tests, used for testing purposes, so that we don't need // to link to tor C files. Uses the system allocator #[cfg(test)] -extern "C" fn tor_malloc_ ( size: usize) -> *mut c_void { +extern "C" fn tor_malloc_(size: usize) -> *mut c_void { use libc::malloc; unsafe { malloc(size) } } @@ -32,7 +32,7 @@ extern "C" fn tor_malloc_ ( size: usize) -> *mut c_void { pub fn allocate_and_copy_string(src: &String) -> *mut c_char { let bytes: &[u8] = src.as_bytes(); - let size = mem::size_of_val::<[u8]>(bytes); + let size = mem::size_of_val::<[u8]>(bytes); let size_one_byte = mem::size_of::<u8>(); // handle integer overflow when adding one to the calculated length @@ -51,7 +51,7 @@ pub fn allocate_and_copy_string(src: &String) -> *mut c_char { // set the last byte as null, using the ability to index into a slice // rather than doing pointer arithmatic - let slice = unsafe { slice::from_raw_parts_mut(dest, size_with_null_byte)}; + let slice = unsafe { slice::from_raw_parts_mut(dest, size_with_null_byte) }; slice[size] = 0; // add a null terminator dest as *mut c_char @@ -70,9 +70,8 @@ mod test { let empty = String::new(); let allocated_empty = allocate_and_copy_string(&empty); - let allocated_empty_rust = unsafe { - CStr::from_ptr(allocated_empty).to_str().unwrap() - }; + let allocated_empty_rust = + unsafe { CStr::from_ptr(allocated_empty).to_str().unwrap() }; assert_eq!("", allocated_empty_rust); @@ -89,9 +88,8 @@ mod test { let empty = String::from("foo bar biz"); let allocated_empty = allocate_and_copy_string(&empty); - let allocated_empty_rust = unsafe { - CStr::from_ptr(allocated_empty).to_str().unwrap() - }; + let allocated_empty_rust = + unsafe { CStr::from_ptr(allocated_empty).to_str().unwrap() }; assert_eq!("foo bar biz", allocated_empty_rust); |