Skip to content

Commit e19fa1c

Browse files
committed
make_batch_type: return Result instead of Option
Result is more idiomatic in Rust to represent a fallible operation. Converting an integer to a Rust enum can definitely fail, so using `Result` is more appropriate than `Option`.
1 parent 02622b1 commit e19fa1c

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

scylla-rust-wrapper/src/batch.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ pub(crate) struct CassBatchState {
3535
pub unsafe extern "C" fn cass_batch_new(
3636
type_: CassBatchType,
3737
) -> CassOwnedExclusivePtr<CassBatch, CMut> {
38-
if let Some(batch_type) = make_batch_type(type_) {
38+
if let Ok(batch_type) = make_batch_type(type_) {
3939
BoxFFI::into_ptr(Box::new(CassBatch {
4040
state: Arc::new(CassBatchState {
4141
batch: Batch::new(batch_type),

scylla-rust-wrapper/src/cass_types.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -898,11 +898,11 @@ pub unsafe extern "C" fn cass_data_type_add_sub_value_type_by_name_n(
898898
}
899899
}
900900

901-
pub(crate) fn make_batch_type(type_: CassBatchType) -> Option<BatchType> {
901+
pub(crate) fn make_batch_type(type_: CassBatchType) -> Result<BatchType, ()> {
902902
match type_ {
903-
CassBatchType::CASS_BATCH_TYPE_LOGGED => Some(BatchType::Logged),
904-
CassBatchType::CASS_BATCH_TYPE_UNLOGGED => Some(BatchType::Unlogged),
905-
CassBatchType::CASS_BATCH_TYPE_COUNTER => Some(BatchType::Counter),
906-
_ => None,
903+
CassBatchType::CASS_BATCH_TYPE_LOGGED => Ok(BatchType::Logged),
904+
CassBatchType::CASS_BATCH_TYPE_UNLOGGED => Ok(BatchType::Unlogged),
905+
CassBatchType::CASS_BATCH_TYPE_COUNTER => Ok(BatchType::Counter),
906+
_ => Err(()),
907907
}
908908
}

0 commit comments

Comments
 (0)