Skip to content

Commit

Permalink
rust - satiate clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremylt committed Sep 23, 2024
1 parent 9a08c60 commit a415e90
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 58 deletions.
17 changes: 10 additions & 7 deletions examples/rust/ex1-volume/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,20 @@ fn example_1(options: opt::Opt) -> libceed::Result<()> {
quiet,
gallery,
} = options;
assert!(dim >= 1 && dim <= 3);
assert!((1..=3).contains(&dim));
assert!(mesh_degree >= 1);
assert!(solution_degree >= 1);
assert!(num_qpts >= 1);
let ncomp_x = dim;
let problem_size: i64;
if problem_size_requested < 0 {
problem_size = if test { 8 * 16 } else { 256 * 1024 };
let problem_size: i64 = if problem_size_requested < 0 {
if test {
8 * 16
} else {
256 * 1024
}
} else {
problem_size = problem_size_requested;
}
problem_size_requested
};

// Summary output
if !quiet {
Expand Down Expand Up @@ -102,7 +105,7 @@ fn example_1(options: opt::Opt) -> libceed::Result<()> {
if dim > 2 {
print!(", nz = {}", num_xyz[2]);
}
print!("\n");
println!();
}

// Build ElemRestriction objects describing the mesh and solution discrete
Expand Down
15 changes: 7 additions & 8 deletions examples/rust/ex2-surface/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,21 +47,20 @@ fn example_2(options: opt::Opt) -> libceed::Result<()> {
quiet,
gallery,
} = options;
assert!(dim >= 1 && dim <= 3);
assert!((0..=3).contains(&dim));
assert!(mesh_degree >= 1);
assert!(solution_degree >= 1);
assert!(num_qpts >= 1);
let ncomp_x = dim;
let problem_size: i64;
if problem_size_requested < 0 {
problem_size = if test {
let problem_size: i64 = if problem_size_requested < 0 {
if test {
16 * 16 * (dim * dim) as i64
} else {
256 * 1024
};
}
} else {
problem_size = problem_size_requested;
}
problem_size_requested
};

// Summary output
if !quiet {
Expand Down Expand Up @@ -107,7 +106,7 @@ fn example_2(options: opt::Opt) -> libceed::Result<()> {
if dim > 2 {
print!(", nz = {}", num_xyz[2]);
}
print!("\n");
println!();
}

// Build ElemRestriction objects describing the mesh and solution discrete
Expand Down
17 changes: 10 additions & 7 deletions examples/rust/ex3-vector-volume/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,20 @@ fn example_3(options: opt::Opt) -> libceed::Result<()> {
quiet,
gallery,
} = options;
assert!(dim >= 1 && dim <= 3);
assert!((0..=3).contains(&dim));
assert!(mesh_degree >= 1);
assert!(solution_degree >= 1);
assert!(num_qpts >= 1);
let ncomp_x = dim;
let problem_size: i64;
if problem_size_requested < 0 {
problem_size = if test { 8 * 16 } else { 256 * 1024 };
let problem_size: i64 = if problem_size_requested < 0 {
if test {
8 * 16
} else {
256 * 1024
}
} else {
problem_size = problem_size_requested;
}
problem_size_requested
};
let ncomp_u = 3;

// Summary output
Expand Down Expand Up @@ -104,7 +107,7 @@ fn example_3(options: opt::Opt) -> libceed::Result<()> {
if dim > 2 {
print!(", nz = {}", num_xyz[2]);
}
print!("\n");
println!();
}

// Build ElemRestriction objects describing the mesh and solution discrete
Expand Down
15 changes: 7 additions & 8 deletions examples/rust/ex4-vector-surface/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,21 +48,20 @@ fn example_4(options: opt::Opt) -> libceed::Result<()> {
quiet,
gallery,
} = options;
assert!(dim >= 1 && dim <= 3);
assert!((0..=3).contains(&dim));
assert!(mesh_degree >= 1);
assert!(solution_degree >= 1);
assert!(num_qpts >= 1);
let ncomp_x = dim;
let problem_size: i64;
if problem_size_requested < 0 {
problem_size = if test {
let problem_size: i64 = if problem_size_requested < 0 {
if test {
16 * 16 * (dim * dim) as i64
} else {
256 * 1024
};
}
} else {
problem_size = problem_size_requested;
}
problem_size_requested
};
let ncomp_u = 3;

// Summary output
Expand Down Expand Up @@ -109,7 +108,7 @@ fn example_4(options: opt::Opt) -> libceed::Result<()> {
if dim > 2 {
print!(", nz = {}", num_xyz[2]);
}
print!("\n");
println!();
}

// Build ElemRestriction objects describing the mesh and solution discrete
Expand Down
2 changes: 1 addition & 1 deletion rust/libceed/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ impl Ceed {

// Call to libCEED
let mut ptr = std::ptr::null_mut();
let mut ierr = unsafe { bind_ceed::CeedInit(c_resource.as_ptr() as *const i8, &mut ptr) };
let mut ierr = unsafe { bind_ceed::CeedInit(c_resource.as_ptr(), &mut ptr) };
if ierr != 0 {
panic!("Error initializing backend resource: {}", resource)
}
Expand Down
32 changes: 16 additions & 16 deletions rust/libceed/src/operator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ impl<'a> OperatorField<'a> {
///
/// // Operator field arguments
/// let ne = 3;
/// let q = 4 as usize;
/// let q = 4_usize;
/// let mut ind: Vec<i32> = vec![0; 2 * ne];
/// for i in 0..ne {
/// ind[2 * i + 0] = i as i32;
Expand Down Expand Up @@ -87,7 +87,7 @@ impl<'a> OperatorField<'a> {
///
/// // Operator field arguments
/// let ne = 3;
/// let q = 4 as usize;
/// let q = 4_usize;
/// let mut ind: Vec<i32> = vec![0; 2 * ne];
/// for i in 0..ne {
/// ind[2 * i + 0] = i as i32;
Expand Down Expand Up @@ -130,7 +130,7 @@ impl<'a> OperatorField<'a> {
let slice = unsafe {
std::slice::from_raw_parts(
&ptr as *const bind_ceed::CeedElemRestriction as *const ElemRestriction,
1 as usize,
1_usize,
)
};
ElemRestrictionOpt::Some(&slice[0])
Expand All @@ -147,7 +147,7 @@ impl<'a> OperatorField<'a> {
///
/// // Operator field arguments
/// let ne = 3;
/// let q = 4 as usize;
/// let q = 4_usize;
/// let mut ind: Vec<i32> = vec![0; 2 * ne];
/// for i in 0..ne {
/// ind[2 * i + 0] = i as i32;
Expand Down Expand Up @@ -188,7 +188,7 @@ impl<'a> OperatorField<'a> {
let slice = unsafe {
std::slice::from_raw_parts(
&ptr as *const bind_ceed::CeedBasis as *const Basis,
1 as usize,
1_usize,
)
};
BasisOpt::Some(&slice[0])
Expand All @@ -205,7 +205,7 @@ impl<'a> OperatorField<'a> {
///
/// // Operator field arguments
/// let ne = 3;
/// let q = 4 as usize;
/// let q = 4_usize;
/// let mut ind: Vec<i32> = vec![0; 2 * ne];
/// for i in 0..ne {
/// ind[2 * i + 0] = i as i32;
Expand Down Expand Up @@ -244,7 +244,7 @@ impl<'a> OperatorField<'a> {
let slice = unsafe {
std::slice::from_raw_parts(
&ptr as *const bind_ceed::CeedVector as *const Vector,
1 as usize,
1_usize,
)
};
VectorOpt::Some(&slice[0])
Expand Down Expand Up @@ -309,7 +309,7 @@ impl<'a> fmt::Display for OperatorCore<'a> {
///
/// // Operator field arguments
/// let ne = 3;
/// let q = 4 as usize;
/// let q = 4_usize;
/// let mut ind: Vec<i32> = vec![0; 2 * ne];
/// for i in 0..ne {
/// ind[2 * i + 0] = i as i32;
Expand Down Expand Up @@ -348,7 +348,7 @@ impl<'a> fmt::Display for Operator<'a> {
///
/// // Sub operator field arguments
/// let ne = 3;
/// let q = 4 as usize;
/// let q = 4_usize;
/// let mut ind: Vec<i32> = vec![0; 2 * ne];
/// for i in 0..ne {
/// ind[2 * i + 0] = i as i32;
Expand Down Expand Up @@ -547,7 +547,7 @@ impl<'a> Operator<'a> {
///
/// // Operator field arguments
/// let ne = 3;
/// let q = 4 as usize;
/// let q = 4_usize;
/// let mut ind: Vec<i32> = vec![0; 2 * ne];
/// for i in 0..ne {
/// ind[2 * i + 0] = i as i32;
Expand Down Expand Up @@ -771,7 +771,7 @@ impl<'a> Operator<'a> {
v: impl Into<VectorOpt<'b>>,
) -> crate::Result<Self> {
let fieldname = CString::new(fieldname).expect("CString::new failed");
let fieldname = fieldname.as_ptr() as *const i8;
let fieldname = fieldname.as_ptr();
let ierr = unsafe {
bind_ceed::CeedOperatorSetField(
self.op_core.ptr,
Expand All @@ -795,7 +795,7 @@ impl<'a> Operator<'a> {
///
/// // Operator field arguments
/// let ne = 3;
/// let q = 4 as usize;
/// let q = 4_usize;
/// let mut ind: Vec<i32> = vec![0; 2 * ne];
/// for i in 0..ne {
/// ind[2 * i + 0] = i as i32;
Expand Down Expand Up @@ -830,7 +830,7 @@ impl<'a> Operator<'a> {
&mut num_inputs,
&mut inputs_ptr,
std::ptr::null_mut() as *mut bind_ceed::CeedInt,
std::ptr::null_mut() as *mut *mut bind_ceed::CeedOperatorField,
std::ptr::null_mut(),
)
};
self.op_core.check_error(ierr)?;
Expand All @@ -851,7 +851,7 @@ impl<'a> Operator<'a> {
///
/// // Operator field arguments
/// let ne = 3;
/// let q = 4 as usize;
/// let q = 4_usize;
/// let mut ind: Vec<i32> = vec![0; 2 * ne];
/// for i in 0..ne {
/// ind[2 * i + 0] = i as i32;
Expand Down Expand Up @@ -884,7 +884,7 @@ impl<'a> Operator<'a> {
bind_ceed::CeedOperatorGetFields(
self.op_core.ptr,
std::ptr::null_mut() as *mut bind_ceed::CeedInt,
std::ptr::null_mut() as *mut *mut bind_ceed::CeedOperatorField,
std::ptr::null_mut(),
&mut num_outputs,
&mut outputs_ptr,
)
Expand Down Expand Up @@ -2079,7 +2079,7 @@ impl<'a> CompositeOperator<'a> {
///
/// // Sub operator field arguments
/// let ne = 3;
/// let q = 4 as usize;
/// let q = 4_usize;
/// let mut ind: Vec<i32> = vec![0; 2 * ne];
/// for i in 0..ne {
/// ind[2 * i + 0] = i as i32;
Expand Down
6 changes: 3 additions & 3 deletions rust/libceed/src/qfunction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ impl<'a> QFunctionField<'a> {
unsafe {
bind_ceed::CeedQFunctionFieldGetEvalMode(self.ptr, &mut mode);
}
crate::EvalMode::from_u32(mode as u32)
crate::EvalMode::from_u32(mode)
}
}

Expand Down Expand Up @@ -476,7 +476,7 @@ impl<'a> QFunctionCore<'a> {
&mut num_inputs,
&mut inputs_ptr,
std::ptr::null_mut() as *mut bind_ceed::CeedInt,
std::ptr::null_mut() as *mut *mut bind_ceed::CeedQFunctionField,
std::ptr::null_mut(),
)
};
self.check_error(ierr)?;
Expand All @@ -495,7 +495,7 @@ impl<'a> QFunctionCore<'a> {
bind_ceed::CeedQFunctionGetFields(
self.ptr,
std::ptr::null_mut() as *mut bind_ceed::CeedInt,
std::ptr::null_mut() as *mut *mut bind_ceed::CeedQFunctionField,
std::ptr::null_mut(),
&mut num_outputs,
&mut outputs_ptr,
)
Expand Down
10 changes: 2 additions & 8 deletions rust/libceed/src/vector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -799,10 +799,7 @@ impl<'a> VectorView<'a> {
)
};
vec.check_error(ierr)?;
Ok(Self {
vec: vec,
array: array,
})
Ok(Self { vec, array })
}
}

Expand Down Expand Up @@ -852,10 +849,7 @@ impl<'a> VectorViewMut<'a> {
)
};
vec.check_error(ierr)?;
Ok(Self {
vec: vec,
array: ptr,
})
Ok(Self { vec, array: ptr })
}
}

Expand Down

0 comments on commit a415e90

Please sign in to comment.