I want to print the instance of Tweet datatype in main function, but the summary trait don't implement the debug trait. Is there any way to implement a trait on trait or any work around. uncommentating the second line and commentating the first line would work because String type implements the Display trait.
#[derive(Debug)]
struct Tweet {
name: String,
}
pub trait Summary {
fn summarize(&self) -> String;
}
impl Summary for Tweet {
fn summarize(&self) -> String {
format!("@{}", &self.name)
}
}
fn summarizeable(x: String) -> impl Summary {
Tweet { name: x }
}
fn main() {
//1.
println!("{:#?}", summarizeable(String::from("Alex")));
//2.println!("{}",summarizeable(String::from("Alex")).summarize());
}
error[E0277]:
impl Summary
doesn't implementstd::fmt::Debug
--> src/main.rs:26:29 | 26 | /1./ println!("{:#?}",summarizeable(String::from("Alex"))); |
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^impl Summary
cannot be formatted using{:?}
because it doesn't implementstd::fmt::Debug
| = help: the traitstd::fmt::Debug
is not implemented forimpl Summary
= note: required bystd::fmt::Debug::fmt
error: aborting due to previous error
For more information about this error, try
rustc --explain E0277
. error: Could not compilep1
.To learn more, run the command again with --verbose.