Santa glared at the terminal, baffled. “A simple println!
! That’s all I needed! Why won’t it work?!” He tugged his beard, fuming. The elves had been cranking out code under his “motivational” leadership, but now even Santa’s Rust “expertise” was falling short.
Bernard, the Lead Elf, leaned over Santa’s shoulder, squinting at the code. “Wait… are those gifts for elves and reindeer too? Are you planning to give everyone presents this year?”
Santa slammed the laptop shut, his cheeks reddening. “It’s supposed to be a surprise! If Prancer finds out, she’ll livestream the announcement before the code even works. Now fix this, Bernard—discreetly.”
Bernard crossed his arms, smirking. “Santa, that’s ambitious. But this code is spaghetti. I’ll fix it—but you owe the elves an extra cocoa break.”
Santa growled. “Fine! Just fix it! And not a word to anyone until it’s done.”
Bernard chuckled, cracking his knuckles. “You got it, boss!”
If Bernard solves this problem, it will be likely that the elves and reindeer get gifts from Santa too, it'll be their lucky year, you just need to write a function so that Santa easily can log the gifts, the function should be able to take in either KidsGift
, ElvesGift
or ReindeerGift
and print them out.
Make sure you update the signature of the display_gift
function to accept any of the types.
If you're stuck or need a starting point, here are some hints to help you along the way!
Display
trait using use std::fmt::Display
.Display
trait.mei28
use std::fmt::{Display, Formatter};pub struct KidsGift { pub name: String,}impl Display for KidsGift { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { write!(f, "{}", self.name) }}pub struct ElvesGift { pub name: String,}impl Display for ElvesGift { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { write!(f, "{}", self.name) }}pub struct ReindeerGift { pub name: String,}impl Display for ReindeerGift { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { write!(f, "{}", self.name) }}pub fn display_gift(gift: impl Display) { println!("{}", gift);}pub fn main() { let kids_gift = KidsGift { name: "toy car".to_string(), }; let elves_gift = ElvesGift { name: "vertical monitor".to_string(), }; let reindeer_gift = ReindeerGift { name: "carrot".to_string(), }; display_gift(&kids_gift); display_gift(&elves_gift); display_gift(&reindeer_gift);}
FlorianGD
use std::fmt::Display;pub struct KidsGift { pub name: String,}impl Display for KidsGift { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!(f, "{}", self.name) }}pub struct ElvesGift { pub name: String,}impl Display for ElvesGift { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!(f, "{}", self.name) }}pub struct ReindeerGift { pub name: String,}impl Display for ReindeerGift { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!(f, "{}", self.name) }}pub fn display_gift<T: Display>(gift: &T) { println!("{}", gift);}pub fn main() { let kids_gift = KidsGift { name: "toy car".to_string(), }; let elves_gift = ElvesGift { name: "vertical monitor".to_string(), }; let reindeer_gift = ReindeerGift { name: "carrot".to_string(), }; display_gift(&kids_gift); display_gift(&elves_gift); display_gift(&reindeer_gift);}
sweet2honey
use std::fmt::Display;use std::fmt::Formatter;pub struct KidsGift { pub name: String,}impl Display for KidsGift { fn fmt(&self, f: &mut Formatter) -> Result<(), std::fmt::Error> { write!(f, "{}", self.name) }}pub struct ElvesGift { pub name: String,}impl Display for ElvesGift { fn fmt(&self, f: &mut Formatter) -> Result<(), std::fmt::Error> { write!(f, "{}", self.name) }}pub struct ReindeerGift { pub name: String,}impl Display for ReindeerGift { fn fmt(&self, f: &mut Formatter) -> Result<(), std::fmt::Error> { write!(f, "{}", self.name) }}pub fn display_gift<T: Display>(gift: T) { println!("{}", gift);}pub fn main() { let kids_gift = KidsGift { name: "toy car".to_string(), }; let elves_gift = ElvesGift { name: "vertical monitor".to_string(), }; let reindeer_gift = ReindeerGift { name: "carrot".to_string(), }; display_gift(&kids_gift); display_gift(&elves_gift); display_gift(&reindeer_gift);}
HSteffensen
use std::fmt::Display;use std::fmt::Formatter;pub struct KidsGift { pub name: String,}impl Display for KidsGift { fn fmt(&self, f: &mut Formatter) -> Result<(), std::fmt::Error> { write!(f, "{}", self.name) }}pub struct ElvesGift { pub name: String,}impl Display for ElvesGift { fn fmt(&self, f: &mut Formatter) -> Result<(), std::fmt::Error> { write!(f, "{}", self.name) }}pub struct ReindeerGift { pub name: String,}impl Display for ReindeerGift { fn fmt(&self, f: &mut Formatter) -> Result<(), std::fmt::Error> { write!(f, "{}", self.name) }}pub fn display_gift<T: Display>(gift: T) { println!("{}", gift);}pub fn main() { let kids_gift = KidsGift { name: "toy car".to_string(), }; let elves_gift = ElvesGift { name: "vertical monitor".to_string(), }; let reindeer_gift = ReindeerGift { name: "carrot".to_string(), }; display_gift(&kids_gift); display_gift(&elves_gift); display_gift(&reindeer_gift);}
josephcopenhaver
use std::fmt;pub struct KidsGift { pub name: String,}impl fmt::Display for KidsGift { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}", self.name) }}pub struct ElvesGift { pub name: String,}impl fmt::Display for ElvesGift { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}", self.name) }}pub struct ReindeerGift { pub name: String,}impl fmt::Display for ReindeerGift { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}", self.name) }}pub fn display_gift(gift: impl fmt::Display) { println!("{}", gift);}pub fn main() { let kids_gift = KidsGift { name: "toy car".to_string(), }; let elves_gift = ElvesGift { name: "vertical monitor".to_string(), }; let reindeer_gift = ReindeerGift { name: "carrot".to_string(), }; display_gift(&kids_gift); display_gift(&elves_gift); display_gift(&reindeer_gift);}
kapaseker
use std::fmt::{Display, Formatter};pub struct KidsGift { pub name: String,}impl Display for KidsGift { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { write!(f, "{}", self.name) }}pub struct ElvesGift { pub name: String,}impl Display for ElvesGift { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { write!(f, "{}", self.name) }}pub struct ReindeerGift { pub name: String,}impl Display for ReindeerGift { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { write!(f, "{}", self.name) }}pub fn display_gift(gift: impl Display) { println!("{}", gift);}pub fn main() { let kids_gift = KidsGift { name: "toy car".to_string(), }; let elves_gift = ElvesGift { name: "vertical monitor".to_string(), }; let reindeer_gift = ReindeerGift { name: "carrot".to_string(), }; display_gift(&kids_gift); display_gift(&elves_gift); display_gift(&reindeer_gift);}
Ferdinanddb
use std::fmt;pub struct KidsGift { pub name: String,}impl fmt::Display for KidsGift { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{}", format!("{}", self.name)) }}pub struct ElvesGift { pub name: String,}impl fmt::Display for ElvesGift { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{}", format!("{}", self.name)) }}pub struct ReindeerGift { pub name: String,}impl fmt::Display for ReindeerGift { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{}", format!("{}", self.name)) }}pub fn display_gift<T: fmt::Display>(gift: T) { println!("{}", gift);}pub fn main() { let kids_gift = KidsGift { name: "toy car".to_string(), }; let elves_gift = ElvesGift { name: "vertical monitor".to_string(), }; let reindeer_gift = ReindeerGift { name: "carrot".to_string(), }; display_gift(&kids_gift); display_gift(&elves_gift); display_gift(&reindeer_gift);}
Sympatron
pub struct KidsGift { pub name: String,}pub struct ElvesGift { pub name: String,}pub struct ReindeerGift { pub name: String,}// impl<'a> Into<&'a str> for &'a KidsGift {// fn into(self) -> &'a str {// &self.name// }// }// impl<'a> Into<&'a str> for &'a ElvesGift {// fn into(self) -> &'a str {// &self.name// }// }// impl<'a> Into<&'a str> for &'a ReindeerGift {// fn into(self) -> &'a str {// &self.name// }// }impl std::fmt::Display for KidsGift { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!(f, "{}", &self.name) }}impl std::fmt::Display for ElvesGift { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!(f, "{}", &self.name) }}impl std::fmt::Display for ReindeerGift { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!(f, "{}", &self.name) }}pub fn display_gift(gift: impl std::fmt::Display) { // let name: &str = gift.into(); println!("{}", gift);}pub fn main() { let kids_gift = KidsGift { name: "toy car".to_string(), }; let elves_gift = ElvesGift { name: "vertical monitor".to_string(), }; let reindeer_gift = ReindeerGift { name: "carrot".to_string(), }; display_gift(&kids_gift); display_gift(&elves_gift); display_gift(&reindeer_gift);}
MGehrmann
pub struct KidsGift { pub name: String,}impl std::fmt::Display for KidsGift { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { write!(f, "{}", self.name) }}pub struct ElvesGift { pub name: String,}impl std::fmt::Display for ElvesGift { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { write!(f, "{}", self.name) }}pub struct ReindeerGift { pub name: String,}impl std::fmt::Display for ReindeerGift { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { write!(f, "{}", self.name) }}pub fn display_gift<T: std::fmt::Display>(gift: &T) { println!("{}", gift);}pub fn main() { let kids_gift = KidsGift { name: "toy car".to_string(), }; let elves_gift = ElvesGift { name: "vertical monitor".to_string(), }; let reindeer_gift = ReindeerGift { name: "carrot".to_string(), }; display_gift(&kids_gift); display_gift(&elves_gift); display_gift(&reindeer_gift);}
sarub0b0
pub struct KidsGift { pub name: String,}impl std::fmt::Display for KidsGift { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { write!(f, "{}", self.name) }}pub struct ElvesGift { pub name: String,}impl std::fmt::Display for ElvesGift { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { write!(f, "{}", self.name) }}pub struct ReindeerGift { pub name: String,}impl std::fmt::Display for ReindeerGift { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { write!(f, "{}", self.name) }}pub fn display_gift<T: std::fmt::Display>(gift: &T) { println!("{}", gift);}pub fn main() { let kids_gift = KidsGift { name: "toy car".to_string(), }; let elves_gift = ElvesGift { name: "vertical monitor".to_string(), }; let reindeer_gift = ReindeerGift { name: "carrot".to_string(), }; display_gift(&kids_gift); display_gift(&elves_gift); display_gift(&reindeer_gift);}
habu1010
use std::fmt;pub struct KidsGift { pub name: String,}pub struct ElvesGift { pub name: String,}pub struct ReindeerGift { pub name: String,}impl fmt::Display for KidsGift { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> { writeln!(f, "{}", self.name) }}impl fmt::Display for ElvesGift { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> { writeln!(f, "{}", self.name) }}impl fmt::Display for ReindeerGift { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> { writeln!(f, "{}", self.name) }}pub fn display_gift<T: fmt::Display>(gift: T) { println!("{}", gift);}pub fn main() { let kids_gift = KidsGift { name: "toy car".to_string(), }; let elves_gift = ElvesGift { name: "vertical monitor".to_string(), }; let reindeer_gift = ReindeerGift { name: "carrot".to_string(), }; display_gift(&kids_gift); display_gift(&elves_gift); display_gift(&reindeer_gift);}
ma3103yd-s
use std::fmt;pub struct KidsGift { pub name: String,}pub struct ElvesGift { pub name: String,}pub struct ReindeerGift { pub name: String,}impl fmt::Display for KidsGift { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{}", &self.name) }}impl fmt::Display for ReindeerGift { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{}", &self.name) }}impl fmt::Display for ElvesGift { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{}", &self.name) }}pub fn display_gift(gift: impl fmt::Display) { println!("{}", gift);}pub fn main() { let kids_gift = KidsGift { name: "toy car".to_string(), }; let elves_gift = ElvesGift { name: "vertical monitor".to_string(), }; let reindeer_gift = ReindeerGift { name: "carrot".to_string(), }; display_gift(&kids_gift); display_gift(&elves_gift); display_gift(&reindeer_gift);}
doroshtapgh
use std::fmt;#[derive(Debug)]pub struct KidsGift { pub name: String,}impl fmt::Display for KidsGift { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}", self.name) }}#[derive(Debug)]pub struct ElvesGift { pub name: String,}impl fmt::Display for ElvesGift { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}", self.name) }}#[derive(Debug)]pub struct ReindeerGift { pub name: String,}impl fmt::Display for ReindeerGift { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}", self.name) }}pub fn display_gift<T: fmt::Display>(gift: T) { println!("{}", gift);}pub fn main() { let kids_gift = KidsGift { name: "toy car".to_string(), }; let elves_gift = ElvesGift { name: "vertical monitor".to_string(), }; let reindeer_gift = ReindeerGift { name: "carrot".to_string(), }; display_gift(&kids_gift); display_gift(&elves_gift); display_gift(&reindeer_gift);}
Ljungg
use std::fmt::{Display, Formatter, Result};pub struct KidsGift { pub name: String,}impl Display for KidsGift { fn fmt(&self, f: &mut Formatter) -> Result { write!(f, "{}", self.name) }}pub struct ElvesGift { pub name: String,}impl Display for ElvesGift { fn fmt(&self, f: &mut Formatter) -> Result { write!(f, "{}", self.name) }}pub struct ReindeerGift { pub name: String,}impl Display for ReindeerGift { fn fmt(&self, f: &mut Formatter) -> Result { write!(f, "{}", self.name) }}pub fn display_gift<T: Display>(gift: T) { println!("{}", gift);}pub fn main() { let kids_gift = KidsGift { name: "toy car".to_string(), }; let elves_gift = ElvesGift { name: "vertical monitor".to_string(), }; let reindeer_gift = ReindeerGift { name: "carrot".to_string(), }; display_gift(&kids_gift); display_gift(&elves_gift); display_gift(&reindeer_gift);}
eguefif
use std::fmt;pub struct KidsGift { pub name: String,}pub struct ElvesGift { pub name: String,}pub struct ReindeerGift { pub name: String,}pub fn display_gift<T: fmt::Display>(gift: T) { println!("{}", gift);}impl fmt::Display for KidsGift { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{}", self.name) }}impl fmt::Display for ElvesGift { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{}", self.name) }}impl fmt::Display for ReindeerGift { fn fmt(&self, f:&mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{}", self.name) }}pub fn main() { let kids_gift = KidsGift { name: "toy car".to_string(), }; let elves_gift = ElvesGift { name: "vertical monitor".to_string(), }; let reindeer_gift = ReindeerGift { name: "carrot".to_string(), }; display_gift(&kids_gift); display_gift(&elves_gift); display_gift(&reindeer_gift);}
Ankit8848
use std::fmt::{Display, Formatter, Result};pub struct KidsGift { pub name: String,}impl Display for KidsGift { fn fmt(&self, f: &mut Formatter<'_>) -> Result { f.write_str(&self.name) }}pub struct ElvesGift { pub name: String,}impl Display for ElvesGift { fn fmt(&self, f: &mut Formatter<'_>) -> Result { f.write_str(&self.name) }}pub struct ReindeerGift { pub name: String,}impl Display for ReindeerGift { fn fmt(&self, f: &mut Formatter<'_>) -> Result { f.write_str(&self.name) }}pub fn display_gift(gift: impl Display) { println!("{}", gift);}pub fn main() { let kids_gift = KidsGift { name: "toy car".to_string(), }; let elves_gift = ElvesGift { name: "vertical monitor".to_string(), }; let reindeer_gift = ReindeerGift { name: "carrot".to_string(), }; display_gift(&kids_gift); display_gift(&elves_gift); display_gift(&reindeer_gift);}
KushnerykPavel
use std::fmt;pub struct KidsGift { pub name: String,}impl std::fmt::Display for KidsGift { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { write!(f, "{}", self.name) }}pub struct ElvesGift { pub name: String,}impl std::fmt::Display for ElvesGift { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { write!(f, "{}", self.name) }}pub struct ReindeerGift { pub name: String,}impl std::fmt::Display for ReindeerGift { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { write!(f, "{}", self.name) }}pub fn display_gift<T: fmt::Display>(gift: T) { println!("{}", gift);}pub fn main() { let kids_gift = KidsGift { name: "toy car".to_string(), }; let elves_gift = ElvesGift { name: "vertical monitor".to_string(), }; let reindeer_gift = ReindeerGift { name: "carrot".to_string(), }; display_gift(&kids_gift); display_gift(&elves_gift); display_gift(&reindeer_gift);}
rjensen
use std::fmt::{Display};pub struct KidsGift { pub name: String,}impl std::fmt::Display for KidsGift { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { write!(f, "{}", self.name) }}pub struct ElvesGift { pub name: String,}impl std::fmt::Display for ElvesGift { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { write!(f, "{}", self.name) }}pub struct ReindeerGift { pub name: String,}impl std::fmt::Display for ReindeerGift { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { write!(f, "{}", self.name) }}pub fn display_gift<T: Display>(gift: T) { println!("{}", gift);}pub fn main() { let kids_gift = KidsGift { name: "toy car".to_string(), }; let elves_gift = ElvesGift { name: "vertical monitor".to_string(), }; let reindeer_gift = ReindeerGift { name: "carrot".to_string(), }; display_gift(&kids_gift); display_gift(&elves_gift); display_gift(&reindeer_gift);}
rony0000013
use std::fmt::Display;pub struct KidsGift { pub name: String,}impl Display for KidsGift { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!(f, "{}", self.name) }}pub struct ElvesGift { pub name: String,}impl Display for ElvesGift { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!(f, "{}", self.name) }}pub struct ReindeerGift { pub name: String,}impl Display for ReindeerGift { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!(f, "{}", self.name) }}pub fn display_gift(gift: impl Display) { println!("{}", gift);}pub fn main() { let kids_gift = KidsGift { name: "toy car".to_string(), }; let elves_gift = ElvesGift { name: "vertical monitor".to_string(), }; let reindeer_gift = ReindeerGift { name: "carrot".to_string(), }; display_gift(&kids_gift); display_gift(&elves_gift); display_gift(&reindeer_gift);}
pagyeman
use std::fmt::Display;pub struct KidsGift { pub name: String,}impl Display for KidsGift { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!(f, "{}", self.name) }}pub struct ElvesGift { pub name: String,}impl Display for ElvesGift { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!(f, "{}", self.name) }}pub struct ReindeerGift { pub name: String,}impl Display for ReindeerGift { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!(f, "{}", self.name) }}pub fn display_gift(gift: impl Display) { println!("{}", gift);}pub fn main() { let kids_gift = KidsGift { name: "toy car".to_string(), }; let elves_gift = ElvesGift { name: "vertical monitor".to_string(), }; let reindeer_gift = ReindeerGift { name: "carrot".to_string(), }; display_gift(&kids_gift); display_gift(&elves_gift); display_gift(&reindeer_gift);}
arm01846
use std::fmt::Display;pub struct KidsGift { pub name: String,}impl Display for KidsGift { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!(f, "{}", self.name) }}pub struct ElvesGift { pub name: String,}impl Display for ElvesGift { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!(f, "{}", self.name) }}pub struct ReindeerGift { pub name: String,}impl Display for ReindeerGift { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!(f, "{}", self.name) }}pub fn display_gift<T: Display>(gift: T) { println!("{}", gift);}pub fn main() { let kids_gift = KidsGift { name: "toy car".to_string(), }; let elves_gift = ElvesGift { name: "vertical monitor".to_string(), }; let reindeer_gift = ReindeerGift { name: "carrot".to_string(), }; display_gift(&kids_gift); display_gift(&elves_gift); display_gift(&reindeer_gift);}
titoeb
#[derive(Debug)]pub struct KidsGift { pub name: String,}impl std::fmt::Display for KidsGift { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { writeln!(f, "{:?}", self) }}#[derive(Debug)]pub struct ElvesGift { pub name: String,}impl std::fmt::Display for ElvesGift { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { writeln!(f, "{:?}", self) }}#[derive(Debug)]pub struct ReindeerGift { pub name: String,}impl std::fmt::Display for ReindeerGift { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { writeln!(f, "{:?}", self) }}pub fn display_gift(gift: &dyn std::fmt::Display) { println!("{}", gift);}pub fn main() { let kids_gift = KidsGift { name: "toy car".to_string(), }; let elves_gift = ElvesGift { name: "vertical monitor".to_string(), }; let reindeer_gift = ReindeerGift { name: "carrot".to_string(), }; display_gift(&kids_gift); display_gift(&elves_gift); display_gift(&reindeer_gift);}
gmvar
use std::fmt;pub struct KidsGift { pub name: String,}pub struct ElvesGift { pub name: String,}pub struct ReindeerGift { pub name: String,}impl fmt::Display for KidsGift { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{}", self.name) }}impl fmt::Display for ElvesGift { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{}", self.name) }}impl fmt::Display for ReindeerGift { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{}", self.name) }}pub fn display_gift(gift: impl fmt::Display) { println!("{}", gift);}pub fn main() { let kids_gift = KidsGift { name: "toy car".to_string(), }; let elves_gift = ElvesGift { name: "vertical monitor".to_string(), }; let reindeer_gift = ReindeerGift { name: "carrot".to_string(), }; display_gift(&kids_gift); display_gift(&elves_gift); display_gift(&reindeer_gift);}
tamanishi
use std::fmt::{Display, Formatter, Result};pub struct KidsGift { pub name: String,}pub struct ElvesGift { pub name: String,}pub struct ReindeerGift { pub name: String,}impl Display for KidsGift { fn fmt(&self, f: &mut Formatter) -> Result { write!(f, "{}", self.name) }}impl Display for ElvesGift { fn fmt(&self, f: &mut Formatter) -> Result { write!(f, "{}", self.name) }}impl Display for ReindeerGift { fn fmt(&self, f: &mut Formatter) -> Result { write!(f, "{}", self.name) }}// pub fn display_gift(gift: Unknown) {pub fn display_gift<T: Display>(gift: T) { println!("{}", gift);}pub fn main() { let kids_gift = KidsGift { name: "toy car".to_string(), }; let elves_gift = ElvesGift { name: "vertical monitor".to_string(), }; let reindeer_gift = ReindeerGift { name: "carrot".to_string(), }; display_gift(&kids_gift); display_gift(&elves_gift); display_gift(&reindeer_gift);}
Nismirno
use std::fmt;pub struct KidsGift { pub name: String,}impl fmt::Display for KidsGift { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{}", self.name) }}pub struct ElvesGift { pub name: String,}impl fmt::Display for ElvesGift { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{}", self.name) }}pub struct ReindeerGift { pub name: String,}impl fmt::Display for ReindeerGift { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{}", self.name) }}pub fn display_gift(gift: &dyn fmt::Display) { println!("{}", gift);}pub fn main() { let kids_gift = KidsGift { name: "toy car".to_string(), }; let elves_gift = ElvesGift { name: "vertical monitor".to_string(), }; let reindeer_gift = ReindeerGift { name: "carrot".to_string(), }; display_gift(&kids_gift); display_gift(&elves_gift); display_gift(&reindeer_gift);}
gsspdev
use std::fmt;pub struct KidsGift { pub name: String,}impl fmt::Display for KidsGift { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}", self.name) }}pub struct ElvesGift { pub name: String,}impl fmt::Display for ElvesGift { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}", self.name) }}pub struct ReindeerGift { pub name: String,}impl fmt::Display for ReindeerGift { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}", self.name) }}pub fn display_gift(gift: impl fmt::Display<>) { println!("{}", gift);}pub fn main() { let kids_gift = KidsGift { name: "toy car".to_string(), }; let elves_gift = ElvesGift { name: "vertical monitor".to_string(), }; let reindeer_gift = ReindeerGift { name: "carrot".to_string(), }; display_gift(&kids_gift); display_gift(&elves_gift); display_gift(&reindeer_gift);}
stanisgo
use std::fmt;pub struct KidsGift { pub name: String,}impl fmt::Display for KidsGift { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}", self.name) }}pub struct ElvesGift { pub name: String,}impl fmt::Display for ElvesGift { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}", self.name) }}pub struct ReindeerGift { pub name: String,}impl fmt::Display for ReindeerGift { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}", self.name) }}pub fn display_gift<T: fmt::Display>(gift: &T) { println!("{}", gift);}pub fn main() { let kids_gift = KidsGift { name: "toy car".to_string(), }; let elves_gift = ElvesGift { name: "vertical monitor".to_string(), }; let reindeer_gift = ReindeerGift { name: "carrot".to_string(), }; display_gift(&kids_gift); display_gift(&elves_gift); display_gift(&reindeer_gift);}
hafihaf123
use std::fmt::{Display, Formatter};use std::fmt;pub struct KidsGift { pub name: String,}impl Display for KidsGift { fn fmt(&self, fmt: &mut Formatter<'_>) -> fmt::Result { fmt.write_str(&self.name) }}pub struct ElvesGift { pub name: String,}impl Display for ElvesGift { fn fmt(&self, fmt: &mut Formatter<'_>) -> fmt::Result { fmt.write_str(&self.name) }}pub struct ReindeerGift { pub name: String,}impl Display for ReindeerGift { fn fmt(&self, fmt: &mut Formatter<'_>) -> fmt::Result { fmt.write_str(&self.name) }}pub fn display_gift<T: Display>(gift: T) { println!("{gift}");}pub fn main() { let kids_gift = KidsGift { name: "toy car".to_string(), }; let elves_gift = ElvesGift { name: "vertical monitor".to_string(), }; let reindeer_gift = ReindeerGift { name: "carrot".to_string(), }; display_gift(&kids_gift); display_gift(&elves_gift); display_gift(&reindeer_gift);}
Burnus
use std::fmt::{Display, Formatter, Result};pub struct KidsGift { pub name: String,}pub struct ElvesGift { pub name: String,}pub struct ReindeerGift { pub name: String,}impl Display for KidsGift { fn fmt(&self, f: &mut Formatter<'_>) -> Result { write!(f, "({}", self.name) }}impl Display for ElvesGift { fn fmt(&self, f: &mut Formatter<'_>) -> Result { write!(f, "({}", self.name) }}impl Display for ReindeerGift { fn fmt(&self, f: &mut Formatter<'_>) -> Result { write!(f, "({}", self.name) }}pub fn display_gift<G: Display>(gift: &G) { println!("{}", gift);}pub fn main() { let kids_gift = KidsGift { name: "toy car".to_string(), }; let elves_gift = ElvesGift { name: "vertical monitor".to_string(), }; let reindeer_gift = ReindeerGift { name: "carrot".to_string(), }; display_gift(&kids_gift); display_gift(&elves_gift); display_gift(&reindeer_gift);}
vaclav0411
use std::fmt::Display;pub struct KidsGift { pub name: String,}impl Display for KidsGift { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!(f, "{}", self.name) }}pub struct ElvesGift { pub name: String,}impl Display for ElvesGift { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!(f, "{}", self.name) }}pub struct ReindeerGift { pub name: String,}impl Display for ReindeerGift { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!(f, "{}", self.name) }}pub fn display_gift<T: Display>(gift: T) { println!("{}", gift);}pub fn main() { let kids_gift = KidsGift { name: "toy car".to_string(), }; let elves_gift = ElvesGift { name: "vertical monitor".to_string(), }; let reindeer_gift = ReindeerGift { name: "carrot".to_string(), }; display_gift(&kids_gift); display_gift(&elves_gift); display_gift(&reindeer_gift);}
joanne-cmd
use std::fmt::Display;use std::fmt;pub struct KidsGift { pub name: String,}pub struct ElvesGift { pub name: String,}pub struct ReindeerGift { pub name: String,}impl Display for KidsGift { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}", self.name) }}impl Display for ElvesGift { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}", self.name) }}impl Display for ReindeerGift { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}", self.name) }}pub fn display_gift<T: fmt::Display>(gift: T) { println!("{}", gift);}pub fn main() { let kids_gift = KidsGift { name: "toy car".to_string(), }; let elves_gift = ElvesGift { name: "vertical monitor".to_string(), }; let reindeer_gift = ReindeerGift { name: "carrot".to_string(), }; display_gift(&kids_gift); display_gift(&elves_gift); display_gift(&reindeer_gift);}
joanne-cmd
use std::fmt::Display;use std::fmt;pub struct KidsGift { pub name: String,}pub struct ElvesGift { pub name: String,}pub struct ReindeerGift { pub name: String,}impl Display for KidsGift { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}", self.name) }}impl Display for ElvesGift { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}", self.name) }}impl Display for ReindeerGift { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}", self.name) }}pub fn display_gift<T: fmt::Display>(gift: T) { println!("{}", gift);}pub fn main() { let kids_gift = KidsGift { name: "toy car".to_string(), }; let elves_gift = ElvesGift { name: "vertical monitor".to_string(), }; let reindeer_gift = ReindeerGift { name: "carrot".to_string(), }; display_gift(&kids_gift); display_gift(&elves_gift); display_gift(&reindeer_gift);}
felipesaruhashi
use std::fmt;pub struct KidsGift { pub name: String,}pub struct ElvesGift { pub name: String,}pub struct ReindeerGift { pub name: String,}impl fmt::Display for KidsGift { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}", self.name) }}impl fmt::Display for ElvesGift { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}", self.name) }}impl fmt::Display for ReindeerGift { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}", self.name) }}pub fn display_gift<T: fmt::Display>(gift: T) { println!("{}", gift);}pub fn main() { let kids_gift = KidsGift { name: "toy car".to_string(), }; let elves_gift = ElvesGift { name: "vertical monitor".to_string(), }; let reindeer_gift = ReindeerGift { name: "carrot".to_string(), }; display_gift(&kids_gift); display_gift(&elves_gift); display_gift(&reindeer_gift);}
KLcpb
use std::fmt;pub struct KidsGift { pub name: String,}pub struct ElvesGift { pub name: String,}pub struct ReindeerGift { pub name: String,}impl fmt::Display for KidsGift { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}", self.name) }}impl fmt::Display for ElvesGift { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}", self.name) }}impl fmt::Display for ReindeerGift { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}", self.name) }}pub fn display_gift<T: fmt::Display>(gift: T) { println!("{}", gift);}pub fn main() { let kids_gift = KidsGift { name: "toy car".to_string(), }; let elves_gift = ElvesGift { name: "vertical monitor".to_string(), }; let reindeer_gift = ReindeerGift { name: "carrot".to_string(), }; display_gift(&kids_gift); display_gift(&elves_gift); display_gift(&reindeer_gift);}
joshvon44
use std::fmt::Display;pub struct KidsGift { pub name: String,}impl Display for KidsGift { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!(f, "{}", self.name) }}pub struct ElvesGift { pub name: String,}impl Display for ElvesGift { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!(f, "{}", self.name) }}pub struct ReindeerGift { pub name: String,}impl Display for ReindeerGift { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!(f, "{}", self.name) }}pub fn display_gift<T: Display>(gift: T) { println!("{}", gift);}pub fn main() { let kids_gift = KidsGift { name: "toy car".to_string(), }; let elves_gift = ElvesGift { name: "vertical monitor".to_string(), }; let reindeer_gift = ReindeerGift { name: "carrot".to_string(), }; display_gift(&kids_gift); display_gift(&elves_gift); display_gift(&reindeer_gift);}
wishkus
use std::fmt;pub struct KidsGift { pub name: String,}pub struct ElvesGift { pub name: String,}pub struct ReindeerGift { pub name: String,}impl fmt::Display for ReindeerGift { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}", self.name) }}impl fmt::Display for ElvesGift { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}", self.name) }}impl fmt::Display for KidsGift { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}", self.name) }}pub fn display_gift<T: fmt::Display>(gift: T) { println!("{}", gift);}pub fn main() { let kids_gift = KidsGift { name: "toy car".to_string(), }; let elves_gift = ElvesGift { name: "vertical monitor".to_string(), }; let reindeer_gift = ReindeerGift { name: "carrot".to_string(), }; display_gift(&kids_gift); display_gift(&elves_gift); display_gift(&reindeer_gift);}
strachan
use std::fmt;pub struct KidsGift { pub name: String,}pub struct ElvesGift { pub name: String,}pub struct ReindeerGift { pub name: String,}impl fmt::Display for KidsGift { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}", self.name) }}impl fmt::Display for ElvesGift { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}", self.name) }}impl fmt::Display for ReindeerGift { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}", self.name) }}pub fn display_gift<T: fmt::Display>(gift: T) { println!("{}", gift);}pub fn main() { let kids_gift = KidsGift { name: "toy car".to_string(), }; let elves_gift = ElvesGift { name: "vertical monitor".to_string(), }; let reindeer_gift = ReindeerGift { name: "carrot".to_string(), }; display_gift(&kids_gift); display_gift(&elves_gift); display_gift(&reindeer_gift);}
strachan
use std::fmt::Display;use std::fmt;pub struct KidsGift { pub name: String,}pub struct ElvesGift { pub name: String,}pub struct ReindeerGift { pub name: String,}impl Display for KidsGift { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}", self.name) }}impl Display for ElvesGift { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}", self.name) }}impl Display for ReindeerGift { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}", self.name) }}pub fn display_gift<T: fmt::Display>(gift: T) { println!("{}", gift);}pub fn main() { let kids_gift = KidsGift { name: "toy car".to_string(), }; let elves_gift = ElvesGift { name: "vertical monitor".to_string(), }; let reindeer_gift = ReindeerGift { name: "carrot".to_string(), }; display_gift(&kids_gift); display_gift(&elves_gift); display_gift(&reindeer_gift);}
chriswmann
use std::fmt;pub struct KidsGift { pub name: String,}pub struct ElvesGift { pub name: String,}pub struct ReindeerGift { pub name: String,}impl fmt::Display for KidsGift { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}", self.name) }}impl fmt::Display for ElvesGift { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}", self.name) }}impl fmt::Display for ReindeerGift { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}", self.name) }}pub fn display_gift<T: fmt::Display>(gift: T) { println!("{}", gift);}pub fn main() { let kids_gift = KidsGift { name: "toy car".to_string(), }; let elves_gift = ElvesGift { name: "vertical monitor".to_string(), }; let reindeer_gift = ReindeerGift { name: "carrot".to_string(), }; display_gift(&kids_gift); display_gift(&elves_gift); display_gift(&reindeer_gift);}
chriswmann
use std::fmt;pub struct KidsGift { pub name: String,}pub struct ElvesGift { pub name: String,}pub struct ReindeerGift { pub name: String,}impl fmt::Display for KidsGift { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}", self.name) }}impl fmt::Display for ElvesGift { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}", self.name) }}impl fmt::Display for ReindeerGift { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}", self.name) }}pub fn display_gift<T: fmt::Display>(gift: T) { println!("{}", gift);}pub fn main() { let kids_gift = KidsGift { name: "toy car".to_string(), }; let elves_gift = ElvesGift { name: "vertical monitor".to_string(), }; let reindeer_gift = ReindeerGift { name: "carrot".to_string(), }; display_gift(&kids_gift); display_gift(&elves_gift); display_gift(&reindeer_gift);}
lulingar
use std::fmt;pub struct KidsGift { pub name: String,}impl fmt::Display for KidsGift { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{}", self.name) }}pub struct ElvesGift { pub name: String,}impl fmt::Display for ElvesGift { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{}", self.name) }}pub struct ReindeerGift { pub name: String,}impl fmt::Display for ReindeerGift { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{}", self.name) }}pub fn display_gift<T: fmt::Display>(gift: T) { println!("{}", gift);}pub fn main() { let kids_gift = KidsGift { name: "toy car".to_string(), }; let elves_gift = ElvesGift { name: "vertical monitor".to_string(), }; let reindeer_gift = ReindeerGift { name: "carrot".to_string(), }; display_gift(&kids_gift); display_gift(&elves_gift); display_gift(&reindeer_gift);}
kanakshilledar
use std::fmt::{Display, Formatter, Result};pub struct KidsGift { pub name: String,}impl Display for KidsGift { fn fmt(&self, f: &mut Formatter<'_>) -> Result { f.write_str(&self.name) }}pub struct ElvesGift { pub name: String,}impl Display for ElvesGift { fn fmt(&self, f: &mut Formatter<'_>) -> Result { f.write_str(&self.name) }}pub struct ReindeerGift { pub name: String,}impl Display for ReindeerGift { fn fmt(&self, f: &mut Formatter<'_>) -> Result { f.write_str(&self.name) }}pub fn display_gift(gift: impl Display) { println!("{}", gift);}pub fn main() { let kids_gift = KidsGift { name: "toy car".to_string(), }; let elves_gift = ElvesGift { name: "vertical monitor".to_string(), }; let reindeer_gift = ReindeerGift { name: "carrot".to_string(), }; display_gift(&kids_gift); display_gift(&elves_gift); display_gift(&reindeer_gift);}
Stephan-Lindner
use std::fmt::{Display, Formatter, Result};pub struct KidsGift { pub name: String,}impl Display for KidsGift { fn fmt(&self, f: &mut Formatter<'_>) -> Result { f.write_str(&self.name) }}pub struct ElvesGift { pub name: String,}impl Display for ElvesGift { fn fmt(&self, f: &mut Formatter<'_>) -> Result { f.write_str(&self.name) }}pub struct ReindeerGift { pub name: String,}impl Display for ReindeerGift { fn fmt(&self, f: &mut Formatter<'_>) -> Result { f.write_str(&self.name) }}pub fn display_gift(gift: impl Display) { println!("{}", gift);}pub fn main() { let kids_gift = KidsGift { name: "toy car".to_string(), }; let elves_gift = ElvesGift { name: "vertical monitor".to_string(), }; let reindeer_gift = ReindeerGift { name: "carrot".to_string(), }; display_gift(&kids_gift); display_gift(&elves_gift); display_gift(&reindeer_gift);}
martynovs
pub struct KidsGift { pub name: String,}pub struct ElvesGift { pub name: String,}pub struct ReindeerGift { pub name: String,}impl std::fmt::Display for KidsGift { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> Result<(), std::fmt::Error> { f.write_str(&self.name) }}impl std::fmt::Display for ElvesGift { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> Result<(), std::fmt::Error> { f.write_str(&self.name) }}impl std::fmt::Display for ReindeerGift { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> Result<(), std::fmt::Error> { f.write_str(&self.name) }}pub fn display_gift(gift: &impl std::fmt::Display) { println!("{}", gift);}pub fn main() { let kids_gift = KidsGift { name: "toy car".to_string(), }; let elves_gift = ElvesGift { name: "vertical monitor".to_string(), }; let reindeer_gift = ReindeerGift { name: "carrot".to_string(), }; display_gift(&kids_gift); display_gift(&elves_gift); display_gift(&reindeer_gift);}
wlabranche
use std::fmt::{Display, Formatter};use std::fmt;pub struct KidsGift { pub name: String,}impl Display for KidsGift { fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { write!(f, "Kid's Gift: {}", self.name) }}pub struct ElvesGift { pub name: String,}impl Display for ElvesGift { fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { write!(f, "Elf's Gift: {}", self.name) }}pub struct ReindeerGift { pub name: String,}impl Display for ReindeerGift { fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { write!(f, "Reindeer's Gift: {}", self.name) }}pub fn display_gift(gift: impl Display) { println!("{}", gift);}pub fn main() { let kids_gift = KidsGift { name: "toy car".to_string(), }; let elves_gift = ElvesGift { name: "vertical monitor".to_string(), }; let reindeer_gift = ReindeerGift { name: "carrot".to_string(), }; display_gift(&kids_gift); display_gift(&elves_gift); display_gift(&reindeer_gift);}
RedNapPanda
use std::fmt;#[derive(Debug)]pub struct KidsGift { pub name: String,}#[derive(Debug)]pub struct ElvesGift { pub name: String,}#[derive(Debug)]pub struct ReindeerGift { pub name: String,}impl fmt::Display for KidsGift { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}", self.name) }}impl fmt::Display for ElvesGift { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}", self.name) }}impl fmt::Display for ReindeerGift { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}", self.name) }}pub fn display_gift(gift: impl fmt::Display) { println!("{}", gift);}pub fn main() { let kids_gift = KidsGift { name: "toy car".to_string(), }; let elves_gift = ElvesGift { name: "vertical monitor".to_string(), }; let reindeer_gift = ReindeerGift { name: "carrot".to_string(), }; display_gift(&kids_gift); display_gift(&elves_gift); display_gift(&reindeer_gift);}
wendko
use std::fmt::{self, Display};pub struct KidsGift { pub name: String,}impl Display for KidsGift { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}", self.name) }}pub struct ElvesGift { pub name: String,}impl Display for ElvesGift { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}", self.name) }}pub struct ReindeerGift { pub name: String,}impl Display for ReindeerGift { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}", self.name) }}pub fn display_gift(gift: impl Display) { println!("{}", gift);}pub fn main() { let kids_gift = KidsGift { name: "toy car".to_string(), }; let elves_gift = ElvesGift { name: "vertical monitor".to_string(), }; let reindeer_gift = ReindeerGift { name: "carrot".to_string(), }; display_gift(&kids_gift); display_gift(&elves_gift); display_gift(&reindeer_gift);}
DominicD
use std::fmt;pub struct KidsGift { pub name: String,}pub struct ElvesGift { pub name: String,}pub struct ReindeerGift { pub name: String,}impl fmt::Display for KidsGift { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.write_str(&self.name) }}impl fmt::Display for ElvesGift { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.write_str(&self.name) }}impl fmt::Display for ReindeerGift { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.write_str(&self.name) }}pub fn display_gift(gift: impl fmt::Display) { println!("{}", gift);}pub fn main() { let kids_gift = KidsGift { name: "toy car".to_string(), }; let elves_gift = ElvesGift { name: "vertical monitor".to_string(), }; let reindeer_gift = ReindeerGift { name: "carrot".to_string(), }; display_gift(&kids_gift); display_gift(&elves_gift); display_gift(&reindeer_gift);}
jsdm13
use std::fmt;pub struct KidsGift { pub name: String,}impl fmt::Display for KidsGift { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}", self.name) }}pub struct ElvesGift { pub name: String,}impl fmt::Display for ElvesGift { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}", self.name) }}pub struct ReindeerGift { pub name: String,}impl fmt::Display for ReindeerGift { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}", self.name) }}pub fn display_gift(gift: impl fmt::Display) { println!("{}", gift);}pub fn main() { let kids_gift = KidsGift { name: "toy car".to_string(), }; let elves_gift = ElvesGift { name: "vertical monitor".to_string(), }; let reindeer_gift = ReindeerGift { name: "carrot".to_string(), }; display_gift(&kids_gift); display_gift(&elves_gift); display_gift(&reindeer_gift);}
seilis
use std::fmt::{Display, Formatter};pub struct KidsGift { pub name: String,}impl Display for KidsGift { fn fmt(&self, f: &mut Formatter) -> Result<(), std::fmt::Error> { write!(f, "{}", &self.name) }}impl Display for ElvesGift { fn fmt(&self, f: &mut Formatter) -> Result<(), std::fmt::Error> { write!(f, "{}", &self.name) }}impl Display for ReindeerGift { fn fmt(&self, f: &mut Formatter) -> Result<(), std::fmt::Error> { write!(f, "{}", &self.name) }}pub struct ElvesGift { pub name: String,}pub struct ReindeerGift { pub name: String,}pub fn display_gift(gift: impl std::fmt::Display) { println!("{}", gift);}pub fn main() { let kids_gift = KidsGift { name: "toy car".to_string(), }; let elves_gift = ElvesGift { name: "vertical monitor".to_string(), }; let reindeer_gift = ReindeerGift { name: "carrot".to_string(), }; display_gift(&kids_gift); display_gift(&elves_gift); display_gift(&reindeer_gift);}