Repository: awslabs/aws-lambda-rust-runtime (language: rust)

Issue:
`lambda_http` fails to compile with `default-features = false`
If you depend on `lambda_http` 0.8.1 with default features set to false, then the following compile errors occur:
```
    Checking lambda_http v0.8.1
error[E0004]: non-exhaustive patterns: type `&LambdaRequest` is non-empty
  --> ~/.cargo/registry/src/index.crates.io-6f17d22bba15001f/lambda_http-0.8.1/src/request.rs:54:15
   |
54 |         match self {
   |               ^^^^
   |
note: `LambdaRequest` defined here
  --> ~/.cargo/registry/src/index.crates.io-6f17d22bba15001f/lambda_http-0.8.1/src/request.rs:38:10
   |
38 | pub enum LambdaRequest {
   |          ^^^^^^^^^^^^^
   = note: the matched value is of type `&LambdaRequest`
   = note: references are always considered inhabited
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern as shown
   |
54 ~         match self {
55 +             _ => todo!(),
56 +         }
   |

error[E0004]: non-exhaustive patterns: type `&RequestOrigin` is non-empty
  --> ~/.cargo/registry/src/index.crates.io-6f17d22bba15001f/lambda_http-0.8.1/src/response.rs:64:15
   |
64 |         match request_origin {
   |               ^^^^^^^^^^^^^^
   |
note: `RequestOrigin` defined here
  --> ~/.cargo/registry/src/index.crates.io-6f17d22bba15001f/lambda_http-0.8.1/src/request.rs:73:10
   |
73 | pub enum RequestOrigin {
   |          ^^^^^^^^^^^^^
   = note: the matched value is of type `&RequestOrigin`
   = note: references are always considered inhabited
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern as shown
   |
64 ~         match request_origin {
65 +             _ => todo!(),
66 +         }
   |

For more information about this error, try `rustc --explain E0004`.
```


Discussion / hints:
This kinda makes sense. You need at least 1 of the features enabled for the crate to work. Feel free to open a PR if you have suggestions on how to fix that.

Fix patch:
diff --git a/lambda-http/src/deserializer.rs b/lambda-http/src/deserializer.rs
index 1771ea7b..a77f68a5 100644
--- a/lambda-http/src/deserializer.rs
+++ b/lambda-http/src/deserializer.rs
@@ -1,8 +1,4 @@
 use crate::request::LambdaRequest;
-use aws_lambda_events::{
-    alb::AlbTargetGroupRequest,
-    apigw::{ApiGatewayProxyRequest, ApiGatewayV2httpRequest, ApiGatewayWebsocketProxyRequest},
-};
 use serde::{de::Error, Deserialize};
 
 const ERROR_CONTEXT: &str = "this function expects a JSON payload from Amazon API Gateway, Amazon Elastic Load Balancer, or AWS Lambda Function URLs, but the data doesn't match any of those services' events";
@@ -17,28 +13,29 @@ impl<'de> Deserialize<'de> for LambdaRequest {
             Err(err) => return Err(err),
         };
         #[cfg(feature = "apigw_rest")]
-        if let Ok(res) =
-            ApiGatewayProxyRequest::deserialize(serde::__private::de::ContentRefDeserializer::<D::Error>::new(&content))
-        {
+        if let Ok(res) = aws_lambda_events::apigw::ApiGatewayProxyRequest::deserialize(
+            serde::__private::de::ContentRefDeserializer::<D::Error>::new(&content),
+        ) {
             return Ok(LambdaRequest::ApiGatewayV1(res));
         }
         #[cfg(feature = "apigw_http")]
-        if let Ok(res) = ApiGatewayV2httpRequest::deserialize(
+        if let Ok(res) = aws_lambda_events::apigw::ApiGatewayV2httpRequest::deserialize(
             serde::__private::de::ContentRefDeserializer::<D::Error>::new(&content),
         ) {
             return Ok(LambdaRequest::ApiGatewayV2(res));
         }
         #[cfg(feature = "alb")]
         if let Ok(res) =
-            AlbTargetGroupRequest::deserialize(serde::__private::de::ContentRefDeserializer::<D::Error>::new(&content))
+            aws_lambda_events::alb::AlbTargetGroupRequest::deserialize(serde::__private::de::ContentRefDeserializer::<
+                D::Error,
+            >::new(&content))
         {
             return Ok(LambdaRequest::Alb(res));
         }
         #[cfg(feature = "apigw_websockets")]
-        if let Ok(res) = ApiGatewayWebsocketProxyRequest::deserialize(serde::__private::de::ContentRefDeserializer::<
-            D::Error,
-        >::new(&content))
-        {
+        if let Ok(res) = aws_lambda_events::apigw::ApiGatewayWebsocketProxyRequest::deserialize(
+            serde::__private::de::ContentRefDeserializer::<D::Error>::new(&content),
+        ) {
             return Ok(LambdaRequest::WebSocket(res));
         }
 
diff --git a/lambda-http/src/request.rs b/lambda-http/src/request.rs
index bdb755ed..ad86e5a5 100644
--- a/lambda-http/src/request.rs
+++ b/lambda-http/src/request.rs
@@ -8,6 +8,12 @@
 //! [`RequestExt`]: crate::RequestExt
 #[cfg(any(feature = "apigw_rest", feature = "apigw_http", feature = "apigw_websockets"))]
 use crate::ext::extensions::{PathParameters, StageVariables};
+#[cfg(any(
+    feature = "apigw_rest",
+    feature = "apigw_http",
+    feature = "alb",
+    feature = "apigw_websockets"
+))]
 use crate::ext::extensions::{QueryStringParameters, RawHttpPath};
 #[cfg(feature = "alb")]
 use aws_lambda_events::alb::{AlbTargetGroupRequest, AlbTargetGroupRequestContext};
@@ -26,7 +32,7 @@ use serde_json::error::Error as JsonError;
 
 use std::future::Future;
 use std::pin::Pin;
-use std::{env, io::Read, mem};
+use std::{env, io::Read};
 use url::Url;
 
 /// Internal representation of an Lambda http event from
@@ -61,6 +67,13 @@ impl LambdaRequest {
             LambdaRequest::Alb { .. } => RequestOrigin::Alb,
             #[cfg(feature = "apigw_websockets")]
             LambdaRequest::WebSocket { .. } => RequestOrigin::WebSocket,
+            #[cfg(not(any(
+                feature = "apigw_rest",
+                feature = "apigw_http",
+                feature = "alb",
+                feature = "apigw_websockets"
+            )))]
+            _ => compile_error!("Either feature `apigw_rest`, `apigw_http`, `alb`, or `apigw_websockets` must be enabled for the `lambda-http` crate."),
         }
     }
 }
@@ -141,8 +154,8 @@ fn into_api_gateway_v2_request(ag: ApiGatewayV2httpRequest) -> http::Request<Bod
         .expect("failed to build request");
 
     // no builder method that sets headers in batch
-    let _ = mem::replace(req.headers_mut(), headers);
-    let _ = mem::replace(req.method_mut(), http_method);
+    let _ = std::mem::replace(req.headers_mut(), headers);
+    let _ = std::mem::replace(req.method_mut(), http_method);
 
     req
 }
@@ -203,8 +216,8 @@ fn into_proxy_request(ag: ApiGatewayProxyRequest) -> http::Request<Body> {
         .expect("failed to build request");
 
     // no builder method that sets headers in batch
-    let _ = mem::replace(req.headers_mut(), headers);
-    let _ = mem::replace(req.method_mut(), http_method);
+    let _ = std::mem::replace(req.headers_mut(), headers);
+    let _ = std::mem::replace(req.method_mut(), http_method);
 
     req
 }
@@ -255,8 +268,8 @@ fn into_alb_request(alb: AlbTargetGroupRequest) -> http::Request<Body> {
         .expect("failed to build request");
 
     // no builder method that sets headers in batch
-    let _ = mem::replace(req.headers_mut(), headers);
-    let _ = mem::replace(req.method_mut(), http_method);
+    let _ = std::mem::replace(req.headers_mut(), headers);
+    let _ = std::mem::replace(req.method_mut(), http_method);
 
     req
 }
@@ -319,8 +332,8 @@ fn into_websocket_request(ag: ApiGatewayWebsocketProxyRequest) -> http::Request<
         .expect("failed to build request");
 
     // no builder method that sets headers in batch
-    let _ = mem::replace(req.headers_mut(), headers);
-    let _ = mem::replace(req.method_mut(), http_method.unwrap_or(http::Method::GET));
+    let _ = std::mem::replace(req.headers_mut(), headers);
+    let _ = std::mem::replace(req.method_mut(), http_method.unwrap_or(http::Method::GET));
 
     req
 }
diff --git a/lambda-http/src/response.rs b/lambda-http/src/response.rs
index 1a2ede5c..a51d1b2d 100644
--- a/lambda-http/src/response.rs
+++ b/lambda-http/src/response.rs
@@ -114,6 +114,13 @@ impl LambdaResponse {
                 headers: headers.clone(),
                 multi_value_headers: headers,
             }),
+            #[cfg(not(any(
+                feature = "apigw_rest",
+                feature = "apigw_http",
+                feature = "alb",
+                feature = "apigw_websockets"
+            )))]
+            _ => compile_error!("Either feature `apigw_rest`, `apigw_http`, `alb`, or `apigw_websockets` must be enabled for the `lambda-http` crate."),
         }
     }
 }


Test patch: