-
-
Notifications
You must be signed in to change notification settings - Fork 909
Labels
good first issueGood for newcomersGood for newcomershelp wantedContributions encouragedContributions encouraged
Description
It would be nice if the "generate dynamic decoder" code action could pick a suitable zero value when generating the decoder if the selected type has a constructor with no arguments:
pub type ReviewOutcome {
Approved
Rejected
Commented
}
fn review_outcome_decoder() -> decode.Decoder(ReviewOutcome) {
use variant <- decode.then(decode.string)
case variant {
"approved" -> decode.success(Approved)
"rejected" -> decode.success(Rejected)
"commented" -> decode.success(Commented)
_ -> decode.failure(todo as "zero value for ReviewOutcome", "ReviewOutcome")
}
}What if, seeing a constructor with no values it could use that directly?
fn review_outcome_decoder() -> decode.Decoder(ReviewOutcome) {
use variant <- decode.then(decode.string)
case variant {
"approved" -> decode.success(Approved)
"rejected" -> decode.success(Rejected)
"commented" -> decode.success(Commented)
- _ -> decode.failure(todo as "zero value for ReviewOutcome", "ReviewOutcome")
+ _ -> decode.failure(Approved, "ReviewOutcome")
}
}Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
good first issueGood for newcomersGood for newcomershelp wantedContributions encouragedContributions encouraged