Skip to content

Commit

Permalink
derive debug where possible (#2142)
Browse files Browse the repository at this point in the history
  • Loading branch information
ibraheemdev committed Apr 9, 2021
1 parent 44a2d22 commit c72d770
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 43 deletions.
8 changes: 1 addition & 7 deletions src/types/form.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ use crate::{
/// })
/// }
/// ```
#[derive(PartialEq, Eq, PartialOrd, Ord)]
#[derive(PartialEq, Eq, PartialOrd, Ord, Debug)]
pub struct Form<T>(pub T);

impl<T> Form<T> {
Expand Down Expand Up @@ -150,12 +150,6 @@ where
}
}

impl<T: fmt::Debug> fmt::Debug for Form<T> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.0.fmt(f)
}
}

impl<T: fmt::Display> fmt::Display for Form<T> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.0.fmt(f)
Expand Down
11 changes: 1 addition & 10 deletions src/types/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use crate::{
/// format!("Request was sent at {}", date.to_string())
/// }
/// ```
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord)]
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Debug)]
pub struct Header<T>(pub T);

impl<T> Header<T> {
Expand All @@ -47,15 +47,6 @@ impl<T> ops::DerefMut for Header<T> {
}
}

impl<T> fmt::Debug for Header<T>
where
T: fmt::Debug,
{
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "Header: {:?}", self.0)
}
}

impl<T> fmt::Display for Header<T>
where
T: fmt::Display,
Expand Down
10 changes: 1 addition & 9 deletions src/types/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ use crate::{
/// })
/// }
/// ```
#[derive(Debug)]
pub struct Json<T>(pub T);

impl<T> Json<T> {
Expand All @@ -96,15 +97,6 @@ impl<T> ops::DerefMut for Json<T> {
}
}

impl<T> fmt::Debug for Json<T>
where
T: fmt::Debug,
{
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "Json: {:?}", self.0)
}
}

impl<T> fmt::Display for Json<T>
where
T: fmt::Display,
Expand Down
10 changes: 2 additions & 8 deletions src/types/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ use crate::{dev::Payload, error::PathError, FromRequest, HttpRequest};
/// format!("Welcome {}!", info.name)
/// }
/// ```
#[derive(PartialEq, Eq, PartialOrd, Ord)]
#[derive(PartialEq, Eq, PartialOrd, Ord, Debug)]
pub struct Path<T>(T);

impl<T> Path<T> {
Expand Down Expand Up @@ -81,12 +81,6 @@ impl<T> From<T> for Path<T> {
}
}

impl<T: fmt::Debug> fmt::Debug for Path<T> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.0.fmt(f)
}
}

impl<T: fmt::Display> fmt::Display for Path<T> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.0.fmt(f)
Expand Down Expand Up @@ -261,7 +255,7 @@ mod tests {
assert_eq!(s.value, "user2");
assert_eq!(
format!("{}, {:?}", s, s),
"MyStruct(name, user2), MyStruct { key: \"name\", value: \"user2\" }"
"MyStruct(name, user2), Path(MyStruct { key: \"name\", value: \"user2\" })"
);
let s = s.into_inner();
assert_eq!(s.value, "user2");
Expand Down
18 changes: 9 additions & 9 deletions src/types/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ use crate::{dev::Payload, error::QueryPayloadError, Error, FromRequest, HttpRequ
/// "OK".to_string()
/// }
/// ```
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord)]
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Debug)]
pub struct Query<T>(pub T);

impl<T> Query<T> {
Expand Down Expand Up @@ -100,12 +100,6 @@ impl<T> ops::DerefMut for Query<T> {
}
}

impl<T: fmt::Debug> fmt::Debug for Query<T> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.0.fmt(f)
}
}

impl<T: fmt::Display> fmt::Display for Query<T> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.0.fmt(f)
Expand Down Expand Up @@ -226,7 +220,10 @@ mod tests {
let mut s = Query::<Id>::from_query(&req.query_string()).unwrap();

assert_eq!(s.id, "test");
assert_eq!(format!("{}, {:?}", s, s), "test, Id { id: \"test\" }");
assert_eq!(
format!("{}, {:?}", s, s),
"test, Query(Id { id: \"test\" })"
);

s.id = "test1".to_string();
let s = s.into_inner();
Expand All @@ -244,7 +241,10 @@ mod tests {

let mut s = Query::<Id>::from_request(&req, &mut pl).await.unwrap();
assert_eq!(s.id, "test");
assert_eq!(format!("{}, {:?}", s, s), "test, Id { id: \"test\" }");
assert_eq!(
format!("{}, {:?}", s, s),
"test, Query(Id { id: \"test\" })"
);

s.id = "test1".to_string();
let s = s.into_inner();
Expand Down

0 comments on commit c72d770

Please sign in to comment.