1
Fork 0

core: split into fmt::Show and fmt::String

fmt::Show is for debugging, and can and should be implemented for
all public types. This trait is used with `{:?}` syntax. There still
exists #[derive(Show)].

fmt::String is for types that faithfully be represented as a String.
Because of this, there is no way to derive fmt::String, all
implementations must be purposeful. It is used by the default format
syntax, `{}`.

This will break most instances of `{}`, since that now requires the type
to impl fmt::String. In most cases, replacing `{}` with `{:?}` is the
correct fix. Types that were being printed specifically for users should
receive a fmt::String implementation to fix this.

Part of #20013

[breaking-change]
This commit is contained in:
Sean McArthur 2014-12-20 00:09:35 -08:00
parent 8efd9901b6
commit 44440e5c18
252 changed files with 1996 additions and 1366 deletions

View file

@ -445,7 +445,7 @@ fn json_input(input: &str) -> Result<Output, String> {
}
};
match json::from_reader(&mut input) {
Err(s) => Err(s.to_string()),
Err(s) => Err(format!("{:?}", s)),
Ok(Json::Object(obj)) => {
let mut obj = obj;
// Make sure the schema is what we expect
@ -505,7 +505,7 @@ fn json_output(krate: clean::Crate, res: Vec<plugins::PluginJson> ,
let crate_json_str = format!("{}", json::as_json(&krate));
let crate_json = match json::from_str(crate_json_str.as_slice()) {
Ok(j) => j,
Err(e) => panic!("Rust generated JSON is invalid: {}", e)
Err(e) => panic!("Rust generated JSON is invalid: {:?}", e)
};
json.insert("crate".to_string(), crate_json);