Skip to content

Commit 901b26e

Browse files
committed
batch: cass_batch_new uses let-else
let-else is the idiomatic way to handle early error returns in Rust, which can make the code cleaner and more readable.
1 parent e19fa1c commit 901b26e

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

scylla-rust-wrapper/src/batch.rs

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,19 +33,20 @@ pub(crate) struct CassBatchState {
3333

3434
#[unsafe(no_mangle)]
3535
pub unsafe extern "C" fn cass_batch_new(
36-
type_: CassBatchType,
36+
typ: CassBatchType,
3737
) -> CassOwnedExclusivePtr<CassBatch, CMut> {
38-
if let Ok(batch_type) = make_batch_type(type_) {
39-
BoxFFI::into_ptr(Box::new(CassBatch {
40-
state: Arc::new(CassBatchState {
41-
batch: Batch::new(batch_type),
42-
bound_values: Vec::new(),
43-
}),
44-
exec_profile: None,
45-
}))
46-
} else {
47-
BoxFFI::null_mut()
48-
}
38+
let Ok(batch_type) = make_batch_type(typ) else {
39+
tracing::error!("Provided invalid batch type to cass_batch_new: {typ:?}");
40+
return BoxFFI::null_mut();
41+
};
42+
43+
BoxFFI::into_ptr(Box::new(CassBatch {
44+
state: Arc::new(CassBatchState {
45+
batch: Batch::new(batch_type),
46+
bound_values: Vec::new(),
47+
}),
48+
exec_profile: None,
49+
}))
4950
}
5051

5152
#[unsafe(no_mangle)]

0 commit comments

Comments
 (0)