diff --git a/rust/trexio/Makefile b/rust/trexio/Makefile index cd8509b..bb6fc05 100644 --- a/rust/trexio/Makefile +++ b/rust/trexio/Makefile @@ -2,7 +2,7 @@ default: src/generated.rs cargo build cargo test -generated.rs: build.py +src/generated.rs: build.py python3 build.py test: default diff --git a/rust/trexio/build.py b/rust/trexio/build.py index f275b1c..f3082fd 100755 --- a/rust/trexio/build.py +++ b/rust/trexio/build.py @@ -88,7 +88,11 @@ use std::ffi::CString; /// This implementation block includes additional functions automatically generated from tables. /// For more details, refer to [TREXIO tables documentation](https://trex-coe.github.io/trexio/trex.html). -impl File {""" ] +impl File { +#![allow(clippy::unnecessary_cast)] +#![allow(clippy::useless_conversion)] +#![allow(clippy::type_complexity)] +""" ] for group in data: group_l = group.lower() @@ -407,12 +411,12 @@ f"/// let two_d_array: Vec<_> = one_d_array.chunks({dim_group}_{dim_element}).co let mut dset_out: Vec<*mut i8> = vec![std::ptr::null_mut(); size]; // Allocate C-style strings and populate dset_out - for i in 0..size{ + for item in dset_out.iter_mut().take(size){ let c_str: *mut i8 = unsafe { std::alloc::alloc_zeroed(std::alloc::Layout::array::(capacity).unwrap()) as *mut i8 }; if c_str.is_null() { return Err(ExitCode::AllocationFailed); } - dset_out[i] = c_str; + *item = c_str; } @@ -461,11 +465,11 @@ f"/// let two_d_array: Vec<_> = one_d_array.chunks({dim_group}_{dim_element}).co pub fn write_{group_l}_{element_l}(&self, data: &[&str]) -> Result<(), ExitCode> { let mut size = 0; // Find longest string - for s in data.iter() { + for s in data { let l = s.len(); size = if l>size {l} else {size}; } - size = size+1; + size += 1; let data_c : Vec = data.iter().map(|&x| string_to_c(x)).collect::>(); let data_c : Vec<*const c_char> = data_c.iter().map(|x| x.as_ptr() as *const c_char).collect::>(); let size : i32 = size.try_into().expect("try_into failed in write_{group}_{element} (size)"); @@ -557,7 +561,7 @@ pub fn write_{group_l}_{element_l}(&self, offset: usize, data: &[{typ}]) -> Resu let mut idx = Vec::::with_capacity({size}*data.len()); let mut val = Vec::::with_capacity(data.len()); - for d in data.iter() { + for d in data { """ + '\n'.join([ f" idx.push(d.{i}.try_into().unwrap());" for i in range(size) ]) + f"\n val.push(d.{size});" + diff --git a/rust/trexio/src/bitfield.rs b/rust/trexio/src/bitfield.rs index de722f8..dd0119c 100644 --- a/rust/trexio/src/bitfield.rs +++ b/rust/trexio/src/bitfield.rs @@ -15,7 +15,7 @@ impl Bitfield { .len() .try_into() .expect("try_into failed in Bitfield::from"); - let orb_list_ptr = orb_list.as_ptr() as *const i32; + let orb_list_ptr: *const i32 = orb_list.as_ptr(); let n_int32: i32 = n_int.try_into().expect("try_into failed in Bitfield::from"); let mut b = vec![0i64; n_int]; let bit_list = b.as_mut_ptr() as *mut c::bitfield_t; @@ -50,7 +50,7 @@ impl Bitfield { pub fn alpha(&self) -> Bitfield { let n_int = self.data.len() / 2; Bitfield { - data: (&self.data[0..n_int]).to_vec(), + data: (self.data[0..n_int]).to_vec(), } } @@ -58,7 +58,7 @@ impl Bitfield { pub fn beta(&self) -> Bitfield { let n_int = self.data.len() / 2; Bitfield { - data: (&self.data[n_int..2 * n_int]).to_vec(), + data: (self.data[n_int..2 * n_int]).to_vec(), } } @@ -86,7 +86,7 @@ impl Bitfield { let d1 = self.as_ptr(); let cap = self.data.len() * 64; let mut list = vec![0i32; cap]; - let list_c = list.as_mut_ptr() as *mut i32; + let list_c: *mut i32 = list.as_mut_ptr(); std::mem::forget(list); let mut occ_num: i32 = 0; @@ -120,10 +120,10 @@ impl Bitfield { let d1 = self.as_ptr(); let cap = self.data.len() / 2 * 64; let mut b = vec![0i32; cap]; - let list_up_c = b.as_mut_ptr() as *mut i32; + let list_up_c: *mut i32 = b.as_mut_ptr(); std::mem::forget(b); let mut b = vec![0i32; cap]; - let list_dn_c = b.as_mut_ptr() as *mut i32; + let list_dn_c: *mut i32 = b.as_mut_ptr(); std::mem::forget(b); let mut occ_num_up: i32 = 0; diff --git a/rust/trexio/src/lib.rs b/rust/trexio/src/lib.rs index 492aa3a..69bf73d 100644 --- a/rust/trexio/src/lib.rs +++ b/rust/trexio/src/lib.rs @@ -192,12 +192,12 @@ impl File { .try_into() .expect("try_into failed in write_determinant_list"); let mut one_d_array: Vec = Vec::with_capacity(determinants.len() * n_int); - for det in determinants.iter() { - for i in det.as_vec().iter() { - one_d_array.push(i.clone()); + for det in determinants { + for i in det.as_vec() { + one_d_array.push(*i); } } - let dset: *const i64 = one_d_array.as_ptr() as *const i64; + let dset: *const i64 = one_d_array.as_ptr(); let rc = unsafe { c::trexio_write_determinant_list(self.ptr, offset, buffer_size, dset) }; rc_return((), rc) } @@ -251,7 +251,7 @@ impl File { .chunks(2 * n_int) .collect::>() .iter() - .map(|x| (Bitfield::from_vec(&x))) + .map(|x| (Bitfield::from_vec(x))) .collect::>(); rc_return(result, rc) }