feat(lambda-events): Improve ergonomics of SqsBatchResponse and KinesisEventResponse
#1063
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
📬 Issue #, if available:
non_exhaustive) #1060✍️ Description of changes
This PR improves the ergonomics of working with
SqsBatchResponseandKinesisEventResponse.Since v1.0, these structs have been marked as
#[non_exhaustive], which means youcan no longer construct them and provide their content in a single expression.
Note
This is also the case for the related structs
SqsBatchItemFailureandKinesisBatchItemFailure.❌ Previous (pre-1.0, now broken) API
The following code used to be valid before 1.0, but no longer compiles:
With
#[non_exhaustive], you now need something slightly more verbose, similar tothe official example in the repo
([advanced-sqs-partial-batch-failures](https://github.com/aws/aws-lambda-rust-runti
me/blob/main/examples/advanced-sqs-partial-batch-failures/src/main.rs)):
This works, but it is more verbose and a bit less ergonomic for a very common usage
pattern.
✅ Proposed (this PR): ergonomic helper API
This PR adds two helper methods to both
SqsBatchResponseandKinesisEventResponse:add_failure(item_identifier)- Add a single failure to the responseset_failures(item_identifiers)- Set multiple failures at once (replacesany existing failures)
Both methods accept flexible input types via
impl Into<String>, so you can pass&str,String, or any other compatible type.SQS Example using
add_failure:SQS Example using
set_failures:Kinesis Example using
add_failure:This keeps the types
#[non_exhaustive]while restoring a convenient anddiscoverable way to build partial batch responses.
🔏 By submitting this pull request
cargo +nightly fmt.cargo clippy --fix.documentation.
license.