-
Notifications
You must be signed in to change notification settings - Fork 333
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 #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.
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 |
Reviewed 6 of 6 files at r1. Comments from Reviewable |
@@ -213,6 +213,16 @@ impl<'a> ParseOptions<'a> { | |||
} | |||
} | |||
|
|||
impl<'a> Debug for ParseOptions<'a> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can just derive Debug on the structs compiled for each feature.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You need to derive Debug in the encoding set macro to get the rest of *_ENCODE_SET types.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, will do.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
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+ |
📌 Commit 81fdb30 has been approved by |
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 -->
☀️ Test successful - status-travis |
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