use std::fmt;
enum LiteralInfo {
String(String),
Integer(i32),
Float(f32),
Long(i64),
Double(f64),
}
impl fmt::Display for LiteralInfo {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "Literal {} ", self )
}
}
fn main() {
println!("main");
let i = LiteralInfo::Integer(42);
println!("{}", i);
let i = LiteralInfo::String("Hello".to_string());
println!("{}", i);
}
It looks such an innocent program but I was a bit surprised that I ended up with stack overflow errors.
The format specifier in fn mut is calling fn mut again. What is the best way to solve this? Thanks.