Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upFix #305 Implement Debug for many types #335
Conversation
For most types it was a simple matter of adding #[derive(Debug)] but ParseOptions needed a manual implementation because the type of log_syntax_violation is Option<&'a Fn(&'static str)> and Fn doesn't implement Debug. log_syntax_violation is formatter as Some(Fn(&'static str)) or None depending upon its value.
Implemented Debug for EncodingOverride as EncodingRef doesn't implement Debug. Field 'encoding' is formatted as Some(EncodingOverride) or None based on its value.
saghm
commented
May 11, 2017
|
Review status: 0 of 6 files reviewed at latest revision, 1 unresolved discussion. src/encoding.rs, line 98 at r1 (raw file):
Could this instead call Comments from Reviewable |
saghm
commented
May 11, 2017
|
Reviewed 6 of 6 files at r1. Comments from Reviewable |
| @@ -213,6 +213,16 @@ impl<'a> ParseOptions<'a> { | |||
| } | |||
| } | |||
|
|
|||
| impl<'a> Debug for ParseOptions<'a> { | |||
This comment has been minimized.
This comment has been minimized.
turnage
May 11, 2017
•
The body of this function can just be
(self.base_url, self.encoding_override).fmt(f)
Edit: I've never done a github review before so if this comment blocks or something feel free to close it with a garbage comment.
This comment has been minimized.
This comment has been minimized.
imor
May 12, 2017
•
Author
Contributor
What about the log_syntax_violation field? Shouldn't it be included? And as it includes a Fn in the type, how is it usually formatted?
| @@ -89,9 +90,19 @@ impl EncodingOverride { | |||
| } | |||
| } | |||
|
|
|||
| #[cfg(feature = "query_encoding")] | |||
| impl Debug for EncodingOverride { | |||
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
imor
May 12, 2017
•
Author
Contributor
Can't derive Debug in this case because encoding field has type Option<EncodingRef> and EncodingRef trait isn't Debug
| @@ -77,7 +77,7 @@ macro_rules! define_encode_set { | |||
| } | |||
|
|
|||
| /// This encode set is used for the path of cannot-be-a-base URLs. | |||
| #[derive(Copy, Clone)] | |||
| #[derive(Copy, Clone, Debug)] | |||
| #[allow(non_camel_case_types)] | |||
| pub struct SIMPLE_ENCODE_SET; | |||
This comment has been minimized.
This comment has been minimized.
turnage
May 11, 2017
You need to derive Debug in the encoding set macro to get the rest of *_ENCODE_SET types.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
dtolnay
commented
May 11, 2017
|
The use std::fmt::{self, Debug};
struct Good { imor: i32 }
impl Debug for Good {
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
formatter.debug_struct("Good")
.field("imor", &self.imor)
.finish()
}
}
struct Bad { imor: i32 }
impl Debug for Bad {
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
write!(formatter, "Bad {{ imor: {:?} }}", self.imor)
}
}
fn main() {
let good = Good { imor: 0 };
let bad = Bad { imor: 0 };
println!("default: {:?}", good);
println!("indented: {:#?}", good);
println!();
println!("default: {:?}", bad);
println!("indented: {:#?}", bad);
}
Is there a way to do these only using |
|
Review status: 5 of 6 files reviewed at latest revision, 4 unresolved discussions. src/encoding.rs, line 98 at r1 (raw file): Previously, saghm (Saghm Rossi) wrote…
Done. Comments from Reviewable |
|
Thanks! @bors-servo r+ |
|
|
Fix #305 Implement Debug for many types For most types it was a simple matter of adding #[derive(Debug)] but ParseOptions needed a manual implementation because the type of log_syntax_violation is Option<&'a Fn(&'static str)> and Fn doesn't implement Debug. log_syntax_violation is formatted as Some(Fn(&'static str)) or None depending upon its value. <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/rust-url/335) <!-- Reviewable:end -->
|
|
imor commentedMay 10, 2017
•
edited by larsbergstrom
For most types it was a simple matter of adding #[derive(Debug)] but
ParseOptions needed a manual implementation because the type of
log_syntax_violation is Option<&'a Fn(&'static str)> and Fn doesn't
implement Debug. log_syntax_violation is formatted as Some(Fn(&'static
str)) or None depending upon its value.
This change is