Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove Problematic Unwraps In Macros #1055

Merged
merged 7 commits into from
Aug 20, 2024
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
Loading