Skip to content

Commit 010eabc

Browse files
committed
cass_iterator_from_collection: avoid unwrap()
The unwrap can be avoided by reordering the code slightly and operating on the `val` directly, not through the `CassBorrowedSharedPtr`.
1 parent fd4259a commit 010eabc

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

scylla-rust-wrapper/src/iterator.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use crate::metadata::{
1313
use crate::query_result::cass_raw_value::CassRawValue;
1414
use crate::query_result::{
1515
CassRawRow, CassResult, CassResultKind, CassResultMetadata, CassRow, CassValue,
16-
NonNullDeserializationError, cass_value_type,
16+
NonNullDeserializationError,
1717
};
1818
use crate::types::{cass_bool_t, cass_false, size_t};
1919

@@ -1157,16 +1157,15 @@ pub unsafe extern "C" fn cass_iterator_from_row<'result>(
11571157
pub unsafe extern "C" fn cass_iterator_from_collection<'result>(
11581158
value: CassBorrowedSharedPtr<'result, CassValue<'result>, CConst>,
11591159
) -> CassOwnedExclusivePtr<CassIterator<'result>, CMut> {
1160-
if RefFFI::is_null(&value) {
1160+
let Some(val) = RefFFI::as_ref(value) else {
1161+
tracing::error!("Provided null value pointer to cass_iterator_from_collection!");
11611162
return BoxFFI::null_mut();
1162-
}
1163+
};
11631164

11641165
// SAFETY: We assume that user provided a valid pointer to the value.
11651166
// The `value.value_type` is a `CassDataType` obtained from `CassResultMetadata`, which is immutable
1166-
// (thus, underlying `get_unchecked()` is safe).
1167-
let value_type = unsafe { cass_value_type(value.borrow()) };
1168-
1169-
let val = RefFFI::as_ref(value).unwrap();
1167+
// (thus, `get_unchecked()` is safe).
1168+
let value_type = unsafe { val.value_type.get_unchecked() }.get_value_type();
11701169

11711170
let iterator_result = match value_type {
11721171
CassValueType::CASS_VALUE_TYPE_SET | CassValueType::CASS_VALUE_TYPE_LIST => {

0 commit comments

Comments
 (0)