中級 › E0277: doesn't implement `std::fmt::Display` の原因と直し方 › パターン5
E0277: doesn't implement `std::fmt::Display` の原因と直し方
自作の構造体を{}(Display)で出力しようとすると、Displayトレイトを実装していない限りE0277エラーになります。
1 #[derive(Debug)] 2 struct Coord { lat: f64, lng: f64 } 3 fn main() { 4 let c = Coord { lat: 35.6, lng: 139.7 }; 5 println!("_____", c); ^ 6 }
error[E0277]: `Coord` doesn't implement `std::fmt::Display`
空欄を埋めて実行を通す
{}と{:?}はどちらもトレイトに基づく表示方法で、実装されていない方を使うとコンパイルエラーになります。
次の問題