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

fix: missing_debug_implementations #41

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion coverage_config_x86_64.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"coverage_score": 87.9, "exclude_path": "", "crate_features": ""}
{"coverage_score": 85.9, "exclude_path": "", "crate_features": ""}
2 changes: 2 additions & 0 deletions src/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const BUFFER_SIZE: usize = 1024;
const SCM_MAX_FD: usize = 253;

/// Describes the state machine of an HTTP connection.
#[derive(Debug)]
enum ConnectionState {
WaitingForRequestLine,
WaitingForHeaders,
Expand All @@ -27,6 +28,7 @@ enum ConnectionState {
}

/// A wrapper over a HTTP Connection.
#[derive(Debug)]
pub struct HttpConnection<T> {
/// A partial request that is still being received.
pending_request: Option<Request>,
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
#![deny(missing_docs)]
#![deny(missing_docs, missing_debug_implementations)]
//! Minimal implementation of the [HTTP/1.0](https://tools.ietf.org/html/rfc1945)
//! and [HTTP/1.1](https://www.ietf.org/rfc/rfc2616.txt) protocols.
//!
Expand Down
12 changes: 12 additions & 0 deletions src/router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// SPDX-License-Identifier: Apache-2.0

use std::collections::hash_map::{Entry, HashMap};
use std::fmt;

use crate::{MediaType, Method, Request, Response, StatusCode, Version};

Expand All @@ -24,6 +25,17 @@ pub struct HttpRoutes<T> {
routes: HashMap<String, Box<dyn EndpointHandler<T> + Sync + Send>>,
}

impl<T> fmt::Debug for HttpRoutes<T> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("HttpRoutes")
.field("server_id", &self.server_id)
.field("prefix", &self.prefix)
.field("media_type", &self.media_type)
.field("routes", &"{ .. }")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changing this to : .field("routes", &self.routes)

and implementing Debug for EndpointHandler which just has :

impl std::fmt::Debug for dyn EndpointHandler{
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        f.debug_struct("EndpointHandler")
        .field("handle_request",&"{..}}")
        .finish()
    }
}

can improve the debug prints to give us the routes strings

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you provide the full code for this change, I am not convinced this is a good solution.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is what I tried:

diff --git a/src/router.rs b/src/router.rs
index 4676459..cc80bf9 100644
--- a/src/router.rs
+++ b/src/router.rs
@@ -16,6 +16,14 @@ pub trait EndpointHandler<T>: Sync + Send {
     fn handle_request(&self, req: &Request, arg: &T) -> Response;
 }
 
+impl<T> fmt::Debug for dyn EndpointHandler<T> + Send + Sync + 'static{
+    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+        f.debug_struct("EndpointHandler")
+            .field("handle_request", &"{ .. }")
+            .finish()
+    }
+}
+
 /// An HTTP routes structure.
 pub struct HttpRoutes<T> {
     server_id: String,
@@ -31,7 +39,7 @@ impl<T> fmt::Debug for HttpRoutes<T> {
             .field("server_id", &self.server_id)
             .field("prefix", &self.prefix)
             .field("media_type", &self.media_type)
-            .field("routes", &"{ .. }")
+            .field("routes", &self.routes)
             .finish()
     }
 }

and the output for this shows:

HttpRoutes {
    server_id: "Mock_Server",
    prefix: "/api/v1",
    media_type: ApplicationJson,
    routes: {
        "GET:/api/v1/func1": EndpointHandler {
            handle_request: "{ .. }",
        },
    },
}

vs below with existing code in PR

HttpRoutes {
    server_id: "Mock_Server",
    prefix: "/api/v1",
    media_type: ApplicationJson,
    routes: "{ .. }",
}

.finish()
}
}

impl<T: Send> HttpRoutes<T> {
/// Create a http request router.
pub fn new(server_id: String, prefix: String) -> Self {
Expand Down
5 changes: 4 additions & 1 deletion src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ impl ServerRequest {
}

/// Wrapper over `Response` which adds an identification token.
#[derive(Debug)]
pub struct ServerResponse {
/// Inner response.
response: Response,
Expand All @@ -74,7 +75,7 @@ impl ServerResponse {

/// Describes the state of the connection as far as data exchange
/// on the stream is concerned.
#[derive(PartialOrd, PartialEq)]
#[derive(Debug, PartialOrd, PartialEq)]
enum ClientConnectionState {
AwaitingIncoming,
AwaitingOutgoing,
Expand All @@ -83,6 +84,7 @@ enum ClientConnectionState {

/// Wrapper over `HttpConnection` which keeps track of yielded
/// requests and absorbed responses.
#[derive(Debug)]
struct ClientConnection<T> {
/// The `HttpConnection` object which handles data exchange.
connection: HttpConnection<T>,
Expand Down Expand Up @@ -249,6 +251,7 @@ impl<T: Read + Write + ScmSocket> ClientConnection<T> {
/// break;
/// }
/// ```
#[derive(Debug)]
pub struct HttpServer {
/// Socket on which we listen for new connections.
socket: UnixListener,
Expand Down