Skip to content

Commit

Permalink
Modify FromUserType and FromRow macros to use expect rather than unwrap
Browse files Browse the repository at this point in the history
  • Loading branch information
Kailokk committed Aug 13, 2024
1 parent bbb2874 commit e43127b
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 6 deletions.
7 changes: 2 additions & 5 deletions scylla-macros/src/from_row.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ pub(crate) fn from_row_derive(tokens_input: TokenStream) -> Result<TokenStream,
#field_name: {
let (col_ix, col_value) = vals_iter
.next()
.unwrap(); // vals_iter size is checked before this code is reached, so
// it is safe to unwrap

.expect("BUG: Size validated iterator did not contain the expected number of values");
<#field_type as FromCqlVal<::std::option::Option<CqlValue>>>::from_cql(col_value)
.map_err(|e| FromRowError::BadCqlVal {
err: e,
Expand All @@ -48,8 +46,7 @@ pub(crate) fn from_row_derive(tokens_input: TokenStream) -> Result<TokenStream,
{
let (col_ix, col_value) = vals_iter
.next()
.unwrap(); // vals_iter size is checked before this code is reached, so
// it is safe to unwrap
.expect("BUG: Size validated iterator did not contain the expected number of values");

<#field_type as FromCqlVal<::std::option::Option<CqlValue>>>::from_cql(col_value)
.map_err(|e| FromRowError::BadCqlVal {
Expand Down
2 changes: 1 addition & 1 deletion scylla-macros/src/from_user_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pub(crate) fn from_user_type_derive(tokens_input: TokenStream) -> Result<TokenSt
// field)
if let Some(received_field_name) = received_field_name {
if received_field_name == stringify!(#field_name) {
let (_, value) = fields_iter.next().unwrap();
let (_, value) = fields_iter.next().expect("BUG: Validated iterator did not contain expected number of values");
value
} else {
None
Expand Down

0 comments on commit e43127b

Please sign in to comment.