Skip to content

Commit b40c011

Browse files
mpindaruMara Pindaru
andauthored
feat(lambda-events): mark public structs/enums as #[non_exhaustive] (#1045)
* feat(lambda-events): mark public structs/enums as #[non_exhaustive] * fix examples --------- Co-authored-by: Mara Pindaru <[email protected]>
1 parent 3c8a8be commit b40c011

File tree

78 files changed

+507
-67
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+507
-67
lines changed

examples/advanced-sqs-partial-batch-failures/src/main.rs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,17 @@ where
9696
}
9797
},
9898
)
99-
.map(|id| BatchItemFailure { item_identifier: id })
99+
.map(|id| {
100+
let mut failure_item = BatchItemFailure::default();
101+
failure_item.item_identifier = id;
102+
failure_item
103+
})
100104
.collect();
101105

102-
Ok(SqsBatchResponse {
103-
batch_item_failures: failure_items,
106+
Ok({
107+
let mut response = SqsBatchResponse::default();
108+
response.batch_item_failures = failure_items;
109+
response
104110
})
105111
}
106112

@@ -140,8 +146,10 @@ mod test {
140146
.unwrap();
141147

142148
let lambda_event = LambdaEvent {
143-
payload: SqsEventObj {
144-
records: vec![msg_to_fail, msg_to_succeed],
149+
payload: {
150+
let mut event_object = SqsEventObj::default();
151+
event_object.records = vec![msg_to_fail, msg_to_succeed];
152+
event_object
145153
},
146154
context: Context::default(),
147155
};

examples/basic-s3-object-lambda-thumbnail/src/main.rs

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -126,24 +126,28 @@ mod tests {
126126
}
127127

128128
fn get_s3_event() -> S3ObjectLambdaEvent {
129-
S3ObjectLambdaEvent {
130-
x_amz_request_id: ("ID".to_string()),
131-
head_object_context: (Some(HeadObjectContext::default())),
132-
list_objects_context: (Some(ListObjectsContext::default())),
133-
get_object_context: (Some(GetObjectContext {
134-
input_s3_url: ("S3_URL".to_string()),
135-
output_route: ("O_ROUTE".to_string()),
136-
output_token: ("O_TOKEN".to_string()),
137-
})),
138-
list_objects_v2_context: (Some(ListObjectsV2Context::default())),
139-
protocol_version: ("VERSION".to_string()),
140-
user_identity: (UserIdentity::default()),
141-
user_request: (UserRequest::default()),
142-
configuration: (Configuration {
143-
access_point_arn: ("APRN".to_string()),
144-
supporting_access_point_arn: ("SAPRN".to_string()),
145-
payload: (json!(null)),
146-
}),
147-
}
129+
let mut event = S3ObjectLambdaEvent::default();
130+
event.x_amz_request_id = "ID".to_string();
131+
event.head_object_context = Some(HeadObjectContext::default());
132+
event.list_objects_context = Some(ListObjectsContext::default());
133+
event.get_object_context = Some({
134+
let mut context = GetObjectContext::default();
135+
context.input_s3_url = "S3_URL".to_string();
136+
context.output_route = "O_ROUTE".to_string();
137+
context.output_token = "O_TOKEN".to_string();
138+
context
139+
});
140+
event.list_objects_v2_context = Some(ListObjectsV2Context::default());
141+
event.protocol_version = "VERSION".to_string();
142+
event.user_identity = UserIdentity::default();
143+
event.user_request = UserRequest::default();
144+
event.configuration = {
145+
let mut configuration = Configuration::default();
146+
configuration.access_point_arn = "APRN".to_string();
147+
configuration.supporting_access_point_arn = "SAPRN".to_string();
148+
configuration.payload = json!(null);
149+
configuration
150+
};
151+
event
148152
}
149153
}

examples/basic-s3-thumbnail/src/main.rs

Lines changed: 44 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -185,46 +185,53 @@ mod tests {
185185
}
186186

187187
fn get_s3_event(event_name: &str, bucket_name: &str, object_key: &str) -> S3Event {
188-
S3Event {
189-
records: (vec![get_s3_event_record(event_name, bucket_name, object_key)]),
190-
}
188+
let mut event = S3Event::default();
189+
event.records = vec![get_s3_event_record(event_name, bucket_name, object_key)];
190+
event
191191
}
192192

193193
fn get_s3_event_record(event_name: &str, bucket_name: &str, object_key: &str) -> S3EventRecord {
194-
let s3_entity = S3Entity {
195-
schema_version: (Some(String::default())),
196-
configuration_id: (Some(String::default())),
197-
bucket: (S3Bucket {
198-
name: (Some(bucket_name.to_string())),
199-
owner_identity: Some(S3UserIdentity {
200-
principal_id: (Some(String::default())),
201-
}),
202-
arn: (Some(String::default())),
203-
}),
204-
object: (S3Object {
205-
key: (Some(object_key.to_string())),
206-
size: (Some(1)),
207-
url_decoded_key: (Some(String::default())),
208-
version_id: (Some(String::default())),
209-
e_tag: (Some(String::default())),
210-
sequencer: (Some(String::default())),
211-
}),
194+
let mut s3_bucket = S3Bucket::default();
195+
s3_bucket.name = (Some(bucket_name.to_string()));
196+
s3_bucket.owner_identity = {
197+
let mut s3_user_identity = S3UserIdentity::default();
198+
s3_user_identity.principal_id = Some(String::default());
199+
Some(s3_user_identity)
212200
};
213-
214-
S3EventRecord {
215-
event_version: (Some(String::default())),
216-
event_source: (Some(String::default())),
217-
aws_region: (Some(String::default())),
218-
event_time: (chrono::DateTime::default()),
219-
event_name: (Some(event_name.to_string())),
220-
principal_id: (S3UserIdentity {
221-
principal_id: (Some("X".to_string())),
222-
}),
223-
request_parameters: (S3RequestParameters {
224-
source_ip_address: (Some(String::default())),
225-
}),
226-
response_elements: (HashMap::new()),
227-
s3: (s3_entity),
228-
}
201+
s3_bucket.arn = Some(String::default());
202+
203+
let mut s3_object = S3Object::default();
204+
s3_object.key = Some(object_key.to_string());
205+
s3_object.size = Some(1);
206+
s3_object.url_decoded_key = Some(String::default());
207+
s3_object.version_id = Some(String::default());
208+
s3_object.e_tag = Some(String::default());
209+
s3_object.sequencer = Some(String::default());
210+
211+
let mut s3_entity = S3Entity::default();
212+
s3_entity.schema_version = Some(String::default());
213+
s3_entity.configuration_id = Some(String::default());
214+
s3_entity.bucket = s3_bucket;
215+
s3_entity.object = s3_object;
216+
217+
let mut s3_event_record = S3EventRecord::default();
218+
s3_event_record.event_version = Some(String::default());
219+
s3_event_record.event_source = Some(String::default());
220+
s3_event_record.aws_region = Some(String::default());
221+
s3_event_record.event_time = chrono::DateTime::default();
222+
s3_event_record.event_name = Some(event_name.to_string());
223+
s3_event_record.principal_id = {
224+
let mut s3_user_identity = S3UserIdentity::default();
225+
s3_user_identity.principal_id = Some("X".to_string());
226+
s3_user_identity
227+
};
228+
s3_event_record.request_parameters = {
229+
let mut s3_request_parameters = S3RequestParameters::default();
230+
s3_request_parameters.source_ip_address = Some(String::default());
231+
s3_request_parameters
232+
};
233+
s3_event_record.response_elements = HashMap::new();
234+
s3_event_record.s3 = s3_entity;
235+
s3_event_record
229236
}
230237
}

lambda-events/src/encodings/http.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ use std::{borrow::Cow, mem::take, ops::Deref, pin::Pin, task::Poll};
6060
///
6161
/// For more information about API Gateway's body types,
6262
/// refer to [this documentation](https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-payload-encodings.html).
63+
#[non_exhaustive]
6364
#[derive(Debug, Default, Eq, PartialEq)]
6465
pub enum Body {
6566
/// An empty body

lambda-events/src/encodings/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ pub use self::http::*;
1717
pub type Error = Box<dyn std::error::Error + Send + Sync>;
1818

1919
/// Binary data encoded in base64.
20+
#[non_exhaustive]
2021
#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
2122
pub struct Base64Data(
2223
#[serde(deserialize_with = "deserialize_base64")]

lambda-events/src/encodings/time.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use serde::{
77
use std::ops::{Deref, DerefMut};
88

99
/// Timestamp with millisecond precision.
10+
#[non_exhaustive]
1011
#[derive(Clone, Default, Debug, Deserialize, Eq, PartialEq, Serialize)]
1112
pub struct MillisecondTimestamp(
1213
#[serde(deserialize_with = "deserialize_milliseconds")]
@@ -29,6 +30,7 @@ impl DerefMut for MillisecondTimestamp {
2930
}
3031

3132
/// Timestamp with second precision.
33+
#[non_exhaustive]
3234
#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
3335
pub struct SecondTimestamp(
3436
#[serde(deserialize_with = "deserialize_seconds")]
@@ -51,6 +53,7 @@ impl DerefMut for SecondTimestamp {
5153
}
5254

5355
/// Duration with second precision.
56+
#[non_exhaustive]
5457
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
5558
pub struct SecondDuration(
5659
#[serde(deserialize_with = "deserialize_duration_seconds")]
@@ -73,6 +76,7 @@ impl DerefMut for SecondDuration {
7376
}
7477

7578
/// Duration with minute precision.
79+
#[non_exhaustive]
7680
#[derive(Clone, Default, Debug, Deserialize, Eq, PartialEq, Serialize)]
7781
pub struct MinuteDuration(
7882
#[serde(deserialize_with = "deserialize_duration_minutes")]

lambda-events/src/event/activemq/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use std::collections::HashMap;
55

66
use crate::custom_serde::deserialize_lambda_map;
77

8+
#[non_exhaustive]
89
#[derive(Debug, Default, Clone, Eq, PartialEq, Deserialize, Serialize)]
910
#[serde(rename_all = "camelCase")]
1011
pub struct ActiveMqEvent {
@@ -22,6 +23,7 @@ pub struct ActiveMqEvent {
2223
pub other: serde_json::Map<String, Value>,
2324
}
2425

26+
#[non_exhaustive]
2527
#[derive(Debug, Default, Clone, Eq, PartialEq, Deserialize, Serialize)]
2628
#[serde(rename_all = "camelCase")]
2729
pub struct ActiveMqMessage {
@@ -59,6 +61,7 @@ pub struct ActiveMqMessage {
5961
pub other: serde_json::Map<String, Value>,
6062
}
6163

64+
#[non_exhaustive]
6265
#[derive(Debug, Default, Clone, Eq, PartialEq, Deserialize, Serialize)]
6366
#[serde(rename_all = "camelCase")]
6467
pub struct ActiveMqDestination {

lambda-events/src/event/alb/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use serde::{Deserialize, Serialize};
1212
use serde_json::Value;
1313

1414
/// `AlbTargetGroupRequest` contains data originating from the ALB Lambda target group integration
15+
#[non_exhaustive]
1516
#[derive(Clone, Debug, Default, Deserialize, PartialEq, Serialize)]
1617
#[serde(rename_all = "camelCase")]
1718
pub struct AlbTargetGroupRequest {
@@ -44,6 +45,7 @@ pub struct AlbTargetGroupRequest {
4445
}
4546

4647
/// `AlbTargetGroupRequestContext` contains the information to identify the load balancer invoking the lambda
48+
#[non_exhaustive]
4749
#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
4850
#[serde(rename_all = "camelCase")]
4951
pub struct AlbTargetGroupRequestContext {
@@ -58,6 +60,7 @@ pub struct AlbTargetGroupRequestContext {
5860
}
5961

6062
/// `ElbContext` contains the information to identify the ARN invoking the lambda
63+
#[non_exhaustive]
6164
#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
6265
#[serde(rename_all = "camelCase")]
6366
pub struct ElbContext {

0 commit comments

Comments
 (0)