Skip to content

Commit

Permalink
Make Debug impls on Response usable
Browse files Browse the repository at this point in the history
  • Loading branch information
bugadani committed Oct 21, 2023
1 parent b1128cd commit 00d559d
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 42 deletions.
27 changes: 27 additions & 0 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,33 @@ where
Tls((&'conn mut (), core::convert::Infallible)), // Variant is impossible to create, but we need it to avoid "unused lifetime" warning
}

#[cfg(feature = "defmt")]
impl<C> defmt::Format for HttpConnection<'_, C>
where
C: Read + Write,
{
fn format(&self, fmt: defmt::Formatter) {
match self {
HttpConnection::Plain(_) => defmt::write!(fmt, "Plain"),
HttpConnection::PlainBuffered(_) => defmt::write!(fmt, "PlainBuffered"),
HttpConnection::Tls(_) => defmt::write!(fmt, "Tls"),
}
}
}

impl<C> core::fmt::Debug for HttpConnection<'_, C>
where
C: Read + Write,
{
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
match self {
HttpConnection::Plain(_) => f.debug_tuple("Plain").finish(),
HttpConnection::PlainBuffered(_) => f.debug_tuple("PlainBuffered").finish(),
HttpConnection::Tls(_) => f.debug_tuple("Tls").finish(),
}
}
}

impl<'conn, T> HttpConnection<'conn, T>
where
T: Read + Write,
Expand Down
45 changes: 3 additions & 42 deletions src/response.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use embedded_io::{Error as _, ErrorType};
use embedded_io_async::{BufRead, Read, Write};
use embedded_io_async::{BufRead, Read};
use heapless::Vec;

use crate::headers::{ContentType, KeepAlive, TransferEncoding};
Expand All @@ -8,6 +8,8 @@ use crate::request::Method;
use crate::Error;

/// Type representing a parsed HTTP response.
#[derive(Debug)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct Response<'buf, C>
where
C: Read,
Expand All @@ -30,47 +32,6 @@ where
raw_body_read: usize,
}

#[cfg(feature = "defmt")]
impl<C> defmt::Format for Response<'_, C>
where
C: Read + Write,
{
fn format(&self, fmt: defmt::Formatter) {
defmt::write!(
fmt,
"Response {{ method = {}, status = {}, content_type = {}, content_length = {}, transfer_encoding = {}, keep_alive = {}, header_buf = {:?}, header_len = {}, raw_body_read = {} }}",
self.method,
self.status,
self.content_type,
self.content_length,
self.transfer_encoding,
self.keep_alive,
self.header_buf,
self.header_len,
self.raw_body_read,
)
}
}

impl<C> core::fmt::Debug for Response<'_, C>
where
C: Read + Write,
{
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
f.debug_struct("Response")
.field("method", &self.method)
.field("status", &self.status)
.field("content_type", &self.content_type)
.field("content_length", &self.content_length)
.field("transfer_encoding", &self.transfer_encoding)
.field("keep_alive", &self.keep_alive)
.field("header_buf", &self.header_buf)
.field("header_len", &self.header_len)
.field("raw_body_read", &self.raw_body_read)
.finish()
}
}

impl<'buf, C> Response<'buf, C>
where
C: Read,
Expand Down

0 comments on commit 00d559d

Please sign in to comment.