“Bernard! Did I tell you? Trait bounds are the greatest thing since reindeer! The Display
trick you pulled yesterday? Pure genius. I’m hooked.”
Bernard shuffled in, already regretting showing Santa Display
. “What now?”
“The gifts won’t wrap themselves! I need a function—generic, reusable, beautiful. We slap on some bounds, and boom, wrapping perfection!”
Bernard peeked at the screen. “Santa, you’ve got mutable and immutable borrows fighting each other. And what’s with this raw pointer?”
Santa grinned. “Bounds solve everything, Bernard! I’ll slap a Display
here, a Debug
there—easy!”
The IDE chimed angrily. “Cannot borrow self
as mutable while also borrowed as immutable.”
Bernard sighed. “Santa, that’s the compiler telling you no.”
Santa glared at the screen. “Warm up the sled. I’m giving the borrow checker a piece of my mind.”
What you need to do is simple, Santa has written a function prepare_gift
, but it doesn't work quite yet. The function must accept anything that implements the Display
and Gift
trait. And the Gift
trait must have a method wrap
that mutates the is_wrapped
field to true
.
Here's what you gotta do:
is_wrapped: bool
.Gift
trait definition, add a method called wrap
.Gift
trait for KidsGift
, ElvesGift
, and ReindeerGift
. Using the wrap
method, it should set is_wrapped
to true
.prepare_gift
function signature to accept any type that implements the Display
and Gift
traits.If you're stuck or need a starting point, here are some hints to help you along the way!
The Gift
trait should have a method wrap
that takes a mutable reference of self
. e.g.
To make a function accept any type that implements multiple traits, you can use the +
operator. e.g.
Make sure the argument takes a mutable reference &mut T
to be able to call the wrap
method since wrap
also mutates the struct.
A1-exe
use std::fmt;// 1. Add the `is_wrapped` field to the gift structspub struct KidsGift { pub name: String, pub is_wrapped: bool,}pub struct ElvesGift { pub name: String, pub is_wrapped: bool,}pub struct ReindeerGift { pub name: String, pub is_wrapped: bool,}pub trait Gift { fn wrap(&mut self);} // 2. Finish the trait definition //impl Gift for KidsGift { fn wrap(&mut self) { self.is_wrapped = true; }}impl Gift for ElvesGift { fn wrap(&mut self) { self.is_wrapped = true; }}impl Gift for ReindeerGift { fn wrap(&mut self) { self.is_wrapped = true; }}// 3. Update the function signaturepub fn prepare_gift<T: fmt::Display + Gift>(gift: &mut T) { println!("Preparing gift for {}", &gift); gift.wrap(); println!("Gift wrapped for {}", &gift);}// 4. Implement the Gift trait to the gift structsimpl 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 mut kids_gift = KidsGift { name: "toy car".to_string(), is_wrapped: false, }; let mut elves_gift = ElvesGift { name: "vertical monitor".to_string(), is_wrapped: false, }; let mut reindeer_gift = ReindeerGift { name: "carrot".to_string(), is_wrapped: false, }; prepare_gift(&mut kids_gift); prepare_gift(&mut elves_gift); prepare_gift(&mut reindeer_gift);}
mei28
use std::fmt;use std::fmt::Display;// 1. Add the `is_wrapped` field to the gift structspub struct KidsGift { pub name: String, pub is_wrapped:bool,}pub struct ElvesGift { pub name: String, pub is_wrapped:bool,}pub struct ReindeerGift { pub name: String, pub is_wrapped:bool,}pub trait Gift { fn wrap(&mut self);} // 2. Finish the trait definition //// 3. Update the function signaturepub fn prepare_gift<T: Gift + Display>(gift: &mut T) { println!("Preparing gift for {}", &gift); gift.wrap(); println!("Gift wrapped for {}", &gift);}// 4. Implement the Gift trait to the gift structsimpl Gift for ElvesGift { fn wrap(&mut self) { self.is_wrapped = true; }}impl Gift for ReindeerGift { fn wrap(&mut self) { self.is_wrapped = true; }}impl Gift for KidsGift { fn wrap(&mut self) { self.is_wrapped = true; }}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 mut kids_gift = KidsGift { name: "toy car".to_string(), is_wrapped: false, }; let mut elves_gift = ElvesGift { name: "vertical monitor".to_string(), is_wrapped: false, }; let mut reindeer_gift = ReindeerGift { name: "carrot".to_string(), is_wrapped: false, }; prepare_gift(&mut kids_gift); prepare_gift(&mut elves_gift); prepare_gift(&mut reindeer_gift);}
FlorianGD
use std::fmt;// 1. Add the `is_wrapped` field to the gift structspub struct KidsGift { pub name: String, pub is_wrapped: bool,}pub struct ElvesGift { pub name: String, pub is_wrapped: bool,}pub struct ReindeerGift { pub name: String, pub is_wrapped: bool,}// 2. Finish the trait definitionpub trait Gift { fn wrap(&mut self) {}}// 3. Update the function signaturepub fn prepare_gift<T: fmt::Display + Gift>(gift: &mut T) { println!("Preparing gift for {}", &gift); gift.wrap(); println!("Gift wrapped for {}", &gift);}// 4. Implement the Gift trait to the gift structsimpl fmt::Display for KidsGift { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}", self.name) }}impl Gift for KidsGift { fn wrap(&mut self) { self.is_wrapped = true; }}impl fmt::Display for ElvesGift { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}", self.name) }}impl Gift for ElvesGift { fn wrap(&mut self) { self.is_wrapped = true; }}impl fmt::Display for ReindeerGift { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}", self.name) }}impl Gift for ReindeerGift { fn wrap(&mut self) { self.is_wrapped = true; }}pub fn main() { let mut kids_gift = KidsGift { name: "toy car".to_string(), is_wrapped: false, }; let mut elves_gift = ElvesGift { name: "vertical monitor".to_string(), is_wrapped: false, }; let mut reindeer_gift = ReindeerGift { name: "carrot".to_string(), is_wrapped: false, }; prepare_gift(&mut kids_gift); prepare_gift(&mut elves_gift); prepare_gift(&mut reindeer_gift);}
sweet2honey
use std::fmt;// 1. Add the `is_wrapped` field to the gift structspub struct KidsGift { pub name: String, pub is_wrapped: bool,}pub struct ElvesGift { pub name: String, pub is_wrapped: bool,}pub struct ReindeerGift { pub name: String, pub is_wrapped: bool,}pub trait Gift { fn wrap(&mut self);}impl Gift for KidsGift { fn wrap(&mut self) { self.is_wrapped = true }}impl Gift for ElvesGift { fn wrap(&mut self) { self.is_wrapped = true }}impl Gift for ReindeerGift { fn wrap(&mut self) { self.is_wrapped = true }}// 3. Update the function signaturepub fn prepare_gift<T: fmt::Display + Gift>(gift: &mut T) { println!("Preparing gift for {}", &gift); gift.wrap(); println!("Gift wrapped for {}", &gift);}// 4. Implement the Gift trait to the gift structsimpl 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 mut kids_gift = KidsGift { name: "toy car".to_string(), is_wrapped: false, }; let mut elves_gift = ElvesGift { name: "vertical monitor".to_string(), is_wrapped: false, }; let mut reindeer_gift = ReindeerGift { name: "carrot".to_string(), is_wrapped: false, }; prepare_gift(&mut kids_gift); prepare_gift(&mut elves_gift); prepare_gift(&mut reindeer_gift);}
HSteffensen
use std::fmt;// 1. Add the `is_wrapped` field to the gift structspub struct KidsGift { pub name: String, pub is_wrapped: bool,}pub struct ElvesGift { pub name: String, pub is_wrapped: bool,}pub struct ReindeerGift { pub name: String, pub is_wrapped: bool,}pub trait Gift // 2. Finish the trait definition //{ fn wrap(&mut self);}impl Gift for KidsGift { fn wrap(&mut self) { self.is_wrapped = true; }}impl Gift for ElvesGift { fn wrap(&mut self) { self.is_wrapped = true; }}impl Gift for ReindeerGift { fn wrap(&mut self) { self.is_wrapped = true; }}// 3. Update the function signaturepub fn prepare_gift<T: fmt::Display + Gift>( gift: &mut T) { println!("Preparing gift for {}", &gift); gift.wrap(); println!("Gift wrapped for {}", &gift);}// 4. Implement the Gift trait to the gift structsimpl 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 mut kids_gift = KidsGift { name: "toy car".to_string(), is_wrapped: false, }; let mut elves_gift = ElvesGift { name: "vertical monitor".to_string(), is_wrapped: false, }; let mut reindeer_gift = ReindeerGift { name: "carrot".to_string(), is_wrapped: false, }; prepare_gift(&mut kids_gift); prepare_gift(&mut elves_gift); prepare_gift(&mut reindeer_gift);}
josephcopenhaver
use std::fmt;// 1. Add the `is_wrapped` field to the gift structspub struct KidsGift { pub name: String, pub is_wrapped: bool,}pub struct ElvesGift { pub name: String, pub is_wrapped: bool,}pub struct ReindeerGift { pub name: String, pub is_wrapped: bool,}pub trait Gift { fn wrap(&mut self);}impl Gift for KidsGift { fn wrap(&mut self) { self.is_wrapped = true }}impl Gift for ElvesGift { fn wrap(&mut self) { self.is_wrapped = true }}impl Gift for ReindeerGift { fn wrap(&mut self) { self.is_wrapped = true }}// 3. Update the function signaturepub fn prepare_gift<T: fmt::Display + Gift>(gift: &mut T) { println!("Preparing gift for {}", &gift); gift.wrap(); println!("Gift wrapped for {}", &gift);}// 4. Implement the Gift trait to the gift structsimpl 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 mut kids_gift = KidsGift { name: "toy car".to_string(), is_wrapped: false, }; let mut elves_gift = ElvesGift { name: "vertical monitor".to_string(), is_wrapped: false, }; let mut reindeer_gift = ReindeerGift { name: "carrot".to_string(), is_wrapped: false, }; prepare_gift(&mut kids_gift); prepare_gift(&mut elves_gift); prepare_gift(&mut reindeer_gift);}
doroshtapgh
use std::fmt;// 1. Add the `is_wrapped` field to the gift structspub struct KidsGift { pub name: String, pub is_wrapped: bool}pub struct ElvesGift { pub name: String, pub is_wrapped: bool}pub struct ReindeerGift { pub name: String, pub is_wrapped: bool}pub trait Gift // 2. Finish the trait definition //{ fn wrap(&mut self);}// 3. Update the function signaturepub fn prepare_gift<T: fmt::Display + Gift>(gift: &mut T) { println!("Preparing gift for {}", &gift); gift.wrap(); println!("Gift wrapped for {}", &gift);}// 4. Implement the Gift trait to the gift structsimpl Gift for KidsGift { fn wrap(&mut self) { self.is_wrapped = true; }}impl Gift for ElvesGift { fn wrap(&mut self) { self.is_wrapped = true; }}impl Gift for ReindeerGift { fn wrap(&mut self) { self.is_wrapped = true; }}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 mut kids_gift = KidsGift { name: "toy car".to_string(), is_wrapped: false, }; let mut elves_gift = ElvesGift { name: "vertical monitor".to_string(), is_wrapped: false, }; let mut reindeer_gift = ReindeerGift { name: "carrot".to_string(), is_wrapped: false, }; prepare_gift(&mut kids_gift); prepare_gift(&mut elves_gift); prepare_gift(&mut reindeer_gift);}
kapaseker
use std::fmt;use std::fmt::Display;// 1. Add the `is_wrapped` field to the gift structspub struct KidsGift { pub name: String, pub is_wrapped:bool,}pub struct ElvesGift { pub name: String, pub is_wrapped:bool,}pub struct ReindeerGift { pub name: String, pub is_wrapped:bool,}pub trait Gift { fn wrap(&mut self);} // 2. Finish the trait definition //// 3. Update the function signaturepub fn prepare_gift<T: Gift + Display>(gift: &mut T) { println!("Preparing gift for {}", &gift); gift.wrap(); println!("Gift wrapped for {}", &gift);}// 4. Implement the Gift trait to the gift structsimpl Gift for ElvesGift { fn wrap(&mut self) { self.is_wrapped = true; }}impl Gift for ReindeerGift { fn wrap(&mut self) { self.is_wrapped = true; }}impl Gift for KidsGift { fn wrap(&mut self) { self.is_wrapped = true; }}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 mut kids_gift = KidsGift { name: "toy car".to_string(), is_wrapped: false, }; let mut elves_gift = ElvesGift { name: "vertical monitor".to_string(), is_wrapped: false, }; let mut reindeer_gift = ReindeerGift { name: "carrot".to_string(), is_wrapped: false, }; prepare_gift(&mut kids_gift); prepare_gift(&mut elves_gift); prepare_gift(&mut reindeer_gift);}
Ferdinanddb
use std::fmt;// 1. Add the `is_wrapped` field to the gift structspub struct KidsGift { pub name: String, pub is_wrapped: bool,}pub struct ElvesGift { pub name: String, pub is_wrapped: bool,}pub struct ReindeerGift { pub name: String, pub is_wrapped: bool,}// 2. Finish the trait definition //pub trait Gift { fn wrap(&mut self);}// 3. Update the function signaturepub fn prepare_gift<T: fmt::Display + Gift>(gift: &mut T) { println!("Preparing gift for {}", &gift); gift.wrap(); println!("Gift wrapped for {}", &gift);}// 4. Implement the Gift trait to the gift structsimpl fmt::Display for KidsGift { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}", self.name) }}impl Gift for KidsGift { fn wrap(&mut self) { self.is_wrapped = true; }}impl fmt::Display for ElvesGift { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}", self.name) }}impl Gift for ElvesGift { fn wrap(&mut self) { self.is_wrapped = true; }}impl fmt::Display for ReindeerGift { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}", self.name) }}impl Gift for ReindeerGift { fn wrap(&mut self) { self.is_wrapped = true; }}pub fn main() { let mut kids_gift = KidsGift { name: "toy car".to_string(), is_wrapped: false, }; let mut elves_gift = ElvesGift { name: "vertical monitor".to_string(), is_wrapped: false, }; let mut reindeer_gift = ReindeerGift { name: "carrot".to_string(), is_wrapped: false, }; prepare_gift(&mut kids_gift); prepare_gift(&mut elves_gift); prepare_gift(&mut reindeer_gift);}
Sympatron
use std::fmt;// 1. Add the `is_wrapped` field to the gift structspub struct KidsGift { pub name: String, pub is_wrapped: bool,}pub struct ElvesGift { pub name: String, pub is_wrapped: bool,}pub struct ReindeerGift { pub name: String, pub is_wrapped: bool,}pub trait Gift { fn wrap(&mut self);}impl Gift for &mut KidsGift { fn wrap(&mut self) { self.is_wrapped = true; }}impl Gift for &mut ElvesGift { fn wrap(&mut self) { self.is_wrapped = true; }}impl Gift for &mut ReindeerGift { fn wrap(&mut self) { self.is_wrapped = true; }}impl Gift for KidsGift { fn wrap(&mut self) { self.is_wrapped = true; }}impl Gift for ElvesGift { fn wrap(&mut self) { self.is_wrapped = true; }}impl Gift for ReindeerGift { fn wrap(&mut self) { self.is_wrapped = true; }} // 2. Finish the trait definition //// 3. Update the function signaturepub fn prepare_gift<T: fmt::Display + Gift>(mut gift: T) { println!("Preparing gift for {}", &gift); gift.wrap(); println!("Gift wrapped for {}", &gift);}// 4. Implement the Gift trait to the gift structsimpl 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 mut kids_gift = KidsGift { name: "toy car".to_string(), is_wrapped: false, }; let mut elves_gift = ElvesGift { name: "vertical monitor".to_string(), is_wrapped: false, }; let mut reindeer_gift = ReindeerGift { name: "carrot".to_string(), is_wrapped: false, }; prepare_gift(&mut kids_gift); prepare_gift(&mut elves_gift); prepare_gift(&mut reindeer_gift);}
MGehrmann
use std::fmt;// 1. Add the `is_wrapped` field to the gift structspub struct KidsGift { pub name: String, pub is_wrapped: bool,}pub struct ElvesGift { pub name: String, pub is_wrapped: bool,}pub struct ReindeerGift { pub name: String, pub is_wrapped: bool,}pub trait Gift { fn wrap(&mut self);}// 3. Update the function signaturepub fn prepare_gift<T: fmt::Display + Gift>(gift: &mut T) { println!("Preparing gift for {}", gift); gift.wrap(); println!("Gift wrapped for {}", gift);}// 4. Implement the Gift trait to the gift structsimpl 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) }}impl Gift for KidsGift { fn wrap(&mut self) { self.is_wrapped = true; }}impl Gift for ElvesGift { fn wrap(&mut self) { self.is_wrapped = true; } }impl Gift for ReindeerGift { fn wrap(&mut self) { self.is_wrapped = true; }}pub fn main() { let mut kids_gift = KidsGift { name: "toy car".to_string(), is_wrapped: false, }; let mut elves_gift = ElvesGift { name: "vertical monitor".to_string(), is_wrapped: false, }; let mut reindeer_gift = ReindeerGift { name: "carrot".to_string(), is_wrapped: false, }; prepare_gift(&mut kids_gift); prepare_gift(&mut elves_gift); prepare_gift(&mut reindeer_gift);}
sarub0b0
use std::fmt;// 1. Add the `is_wrapped` field to the gift structspub struct KidsGift { pub name: String, pub is_wrapped: bool,}pub struct ElvesGift { pub name: String, pub is_wrapped: bool,}pub struct ReindeerGift { pub name: String, pub is_wrapped: bool,}pub trait Gift { fn wrap(&mut self);}impl Gift for KidsGift { fn wrap(&mut self) { self.is_wrapped = true; }}impl Gift for ElvesGift { fn wrap(&mut self) { self.is_wrapped = true; } }impl Gift for ReindeerGift { fn wrap(&mut self) { self.is_wrapped = true; }}// 3. Update the function signaturepub fn prepare_gift<T: fmt::Display + Gift>(gift: &mut T) { println!("Preparing gift for {}", gift); gift.wrap(); println!("Gift wrapped for {}", gift);}// 4. Implement the Gift trait to the gift structsimpl 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 mut kids_gift = KidsGift { name: "toy car".to_string(), is_wrapped: false, }; let mut elves_gift = ElvesGift { name: "vertical monitor".to_string(), is_wrapped: false, }; let mut reindeer_gift = ReindeerGift { name: "carrot".to_string(), is_wrapped: false, }; prepare_gift(&mut kids_gift); prepare_gift(&mut elves_gift); prepare_gift(&mut reindeer_gift);}
rjensen
use std::fmt;// 1. Add the `is_wrapped` field to the gift structspub struct KidsGift { pub name: String, pub is_wrapped: bool,}pub struct ElvesGift { pub name: String, pub is_wrapped: bool,}pub struct ReindeerGift { pub name: String, pub is_wrapped: bool,}pub trait Gift { // 2. Finish the trait definition // fn wrap(&mut self);}// 3. Update the function signaturepub fn prepare_gift<T: fmt::Display + Gift>(gift: &mut T) { println!("Preparing gift for {}", &gift); gift.wrap(); println!("Gift wrapped for {}", &gift);}// 4. Implement the Gift trait to the gift structsimpl Gift for KidsGift { fn wrap(&mut self) { self.is_wrapped = true; }}impl Gift for ElvesGift { fn wrap(&mut self) { self.is_wrapped = true; }}impl Gift for ReindeerGift { fn wrap(&mut self) { self.is_wrapped = true; }}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 mut kids_gift = KidsGift { name: "toy car".to_string(), is_wrapped: false, }; let mut elves_gift = ElvesGift { name: "vertical monitor".to_string(), is_wrapped: false, }; let mut reindeer_gift = ReindeerGift { name: "carrot".to_string(), is_wrapped: false, }; prepare_gift(&mut kids_gift); prepare_gift(&mut elves_gift); prepare_gift(&mut reindeer_gift);}
Ljungg
use std::fmt;//// Add the new field to the structs is_wrapped: bool.// Finish the Gift trait definition, add a method called wrap.// Implement the Gift trait for KidsGift, ElvesGift, and ReindeerGift. Using the wrap method, it should set is_wrapped to true.// Update the prepare_gift function signature to accept any type that implements the Display and Gift traits.//// 1. Add the `is_wrapped` field to the gift structspub struct KidsGift { pub name: String, pub is_wrapped: bool,}pub struct ElvesGift { pub name: String, pub is_wrapped: bool,}pub struct ReindeerGift { pub name: String, pub is_wrapped: bool,}pub trait Gift { fn wrap(&mut self);}// 3. Update the function signaturepub fn prepare_gift<T: fmt::Display + Gift>(gift: &mut T) { println!("Preparing gift for {}", &gift); gift.wrap(); println!("Gift wrapped for {}", &gift);}// 4. Implement the Gift trait to the gift structsimpl Gift for KidsGift { fn wrap(&mut self) { self.is_wrapped = true; }}impl Gift for ElvesGift { fn wrap(&mut self) { self.is_wrapped = true; }}impl Gift for ReindeerGift { fn wrap(&mut self) { self.is_wrapped = true; }}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 mut kids_gift = KidsGift { name: "toy car".to_string(), is_wrapped: false, }; let mut elves_gift = ElvesGift { name: "vertical monitor".to_string(), is_wrapped: false, }; let mut reindeer_gift = ReindeerGift { name: "carrot".to_string(), is_wrapped: false, }; prepare_gift(&mut kids_gift); prepare_gift(&mut elves_gift); prepare_gift(&mut reindeer_gift);}
habu1010
use std::fmt;// 1. Add the `is_wrapped` field to the gift structspub struct KidsGift { pub name: String, pub is_wrapped: bool,}pub struct ElvesGift { pub name: String, pub is_wrapped: bool,}pub struct ReindeerGift { pub name: String, pub is_wrapped: bool,}// 2. Finish the trait definition //pub trait Gift { fn wrap(&mut self);}// 3. Update the function signaturepub fn prepare_gift<T: fmt::Display + Gift>(gift: &mut T) { println!("Preparing gift for {}", &gift); gift.wrap(); println!("Gift wrapped for {}", &gift);}// 4. Implement the Gift trait to the gift structsimpl Gift for KidsGift { fn wrap(&mut self) { self.is_wrapped = true; }}impl Gift for ElvesGift{ fn wrap(&mut self) { self.is_wrapped = true; }}impl Gift for ReindeerGift { fn wrap(&mut self) { self.is_wrapped = true; }}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 mut kids_gift = KidsGift { name: "toy car".to_string(), is_wrapped: false, }; let mut elves_gift = ElvesGift { name: "vertical monitor".to_string(), is_wrapped: false, }; let mut reindeer_gift = ReindeerGift { name: "carrot".to_string(), is_wrapped: false, }; prepare_gift(&mut kids_gift); prepare_gift(&mut elves_gift); prepare_gift(&mut reindeer_gift);}
ma3103yd-s
use std::fmt;// 1. Add the `is_wrapped` field to the gift structspub struct KidsGift { pub name: String, pub is_wrapped: bool,}pub struct ElvesGift { pub name: String, pub is_wrapped: bool,}pub struct ReindeerGift { pub name: String, pub is_wrapped: bool,}pub trait Gift // 2. Finish the trait definition //{ fn wrap(&mut self);}// 3. Update the function signaturepub fn prepare_gift<T: fmt::Display + Gift>(mut gift: T) { println!("Preparing gift for {}", &gift); gift.wrap(); println!("Gift wrapped for {}", &gift);}// 4. Implement the Gift trait to the gift structsimpl 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) }}impl Gift for KidsGift { fn wrap(&mut self) { self.is_wrapped = true; }}impl Gift for ReindeerGift { fn wrap(&mut self) { self.is_wrapped = true; }}impl Gift for ElvesGift { fn wrap(&mut self) { self.is_wrapped = true; }}impl Gift for &mut KidsGift { fn wrap(&mut self) { self.is_wrapped = true; }}impl Gift for &mut ReindeerGift { fn wrap(&mut self) { self.is_wrapped = true; }}impl Gift for &mut ElvesGift { fn wrap(&mut self) { self.is_wrapped = true; }}pub fn main() { let mut kids_gift = KidsGift { name: "toy car".to_string(), is_wrapped: false, }; let mut elves_gift = ElvesGift { name: "vertical monitor".to_string(), is_wrapped: false, }; let mut reindeer_gift = ReindeerGift { name: "carrot".to_string(), is_wrapped: false, }; prepare_gift(&mut kids_gift); prepare_gift(&mut elves_gift); prepare_gift(&mut reindeer_gift);}
eguefif
use std::fmt;// 1. Add the `is_wrapped` field to the gift structspub struct KidsGift { pub name: String, pub is_wrapped: bool}pub struct ElvesGift { pub name: String, pub is_wrapped: bool}pub struct ReindeerGift { pub name: String, pub is_wrapped: bool}pub trait Gift {// 2. Finish the trait definition // fn wrap(&mut self);}// 3. Update the function signaturepub fn prepare_gift<T: fmt::Display + Gift>(gift: &mut T) { println!("Preparing gift for {}", &gift); gift.wrap(); println!("Gift wrapped for {}", &gift);}// 4. Implement the Gift trait to the gift structsimpl 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) }}impl Gift for KidsGift { fn wrap(&mut self) { self.is_wrapped = true; }}impl Gift for ElvesGift { fn wrap(&mut self) { self.is_wrapped = true; }}impl Gift for ReindeerGift { fn wrap(&mut self) { self.is_wrapped = true; }}pub fn main() { let mut kids_gift = KidsGift { name: "toy car".to_string(), is_wrapped: false, }; let mut elves_gift = ElvesGift { name: "vertical monitor".to_string(), is_wrapped: false, }; let mut reindeer_gift = ReindeerGift { name: "carrot".to_string(), is_wrapped: false, }; prepare_gift(&mut kids_gift); prepare_gift(&mut elves_gift); prepare_gift(&mut reindeer_gift);}
Ankit8848
use std::fmt;// 1. Add the `is_wrapped` field to the gift structspub struct KidsGift { pub name: String, pub is_wrapped: bool,}pub struct ElvesGift { pub name: String, pub is_wrapped: bool,}pub struct ReindeerGift { pub name: String, pub is_wrapped: bool,}pub trait Gift { // 2. Finish the trait definition // fn wrap(&mut self);} // 3. Update the function signaturepub fn prepare_gift<T: fmt::Display + Gift>(gift: &mut T) { println!("Preparing gift for {}", &gift); gift.wrap(); println!("Gift wrapped for {}", &gift);}// 4. Implement the Gift trait to the gift structsimpl fmt::Display for KidsGift { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}", self.name) }}impl Gift for KidsGift { fn wrap(&mut self) { self.is_wrapped = true }}impl fmt::Display for ElvesGift { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}", self.name) }}impl Gift for ElvesGift { fn wrap(&mut self) { self.is_wrapped = true }}impl fmt::Display for ReindeerGift { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}", self.name) }}impl Gift for ReindeerGift { fn wrap(&mut self) { self.is_wrapped = true }}pub fn main() { let mut kids_gift = KidsGift { name: "toy car".to_string(), is_wrapped: false, }; let mut elves_gift = ElvesGift { name: "vertical monitor".to_string(), is_wrapped: false, }; let mut reindeer_gift = ReindeerGift { name: "carrot".to_string(), is_wrapped: false, }; prepare_gift(&mut kids_gift); prepare_gift(&mut elves_gift); prepare_gift(&mut reindeer_gift);}
KushnerykPavel
use std::fmt;// 1. Add the `is_wrapped` field to the gift structspub struct KidsGift { pub name: String, pub is_wrapped: bool,}pub struct ElvesGift { pub name: String, pub is_wrapped: bool,}pub struct ReindeerGift { pub name: String, pub is_wrapped: bool,}pub trait Gift { // 2. Finish the trait definition // fn wrap(&mut self);} // 3. Update the function signaturepub fn prepare_gift<T: fmt::Display + Gift>(gift: &mut T) { println!("Preparing gift for {}", &gift); gift.wrap(); println!("Gift wrapped for {}", &gift);}// 4. Implement the Gift trait to the gift structsimpl fmt::Display for KidsGift { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}", self.name) }}impl Gift for KidsGift { fn wrap(&mut self) { self.is_wrapped = true }}impl fmt::Display for ElvesGift { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}", self.name) }}impl Gift for ElvesGift { fn wrap(&mut self) { self.is_wrapped = true }}impl fmt::Display for ReindeerGift { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}", self.name) }}impl Gift for ReindeerGift { fn wrap(&mut self) { self.is_wrapped = true }}pub fn main() { let mut kids_gift = KidsGift { name: "toy car".to_string(), is_wrapped: false, }; let mut elves_gift = ElvesGift { name: "vertical monitor".to_string(), is_wrapped: false, }; let mut reindeer_gift = ReindeerGift { name: "carrot".to_string(), is_wrapped: false, }; prepare_gift(&mut kids_gift); prepare_gift(&mut elves_gift); prepare_gift(&mut reindeer_gift);}
rony0000013
use std::fmt;// 1. Add the `is_wrapped` field to the gift structspub struct KidsGift { pub name: String, pub is_wrapped: bool,}pub struct ElvesGift { pub name: String, pub is_wrapped: bool,}pub struct ReindeerGift { pub name: String, pub is_wrapped: bool,}pub trait Gift { fn wrap(&mut self);}// 3. Update the function signaturepub fn prepare_gift<T: fmt::Display + Gift>(gift: &mut T) { println!("Preparing gift for {}", &gift); gift.wrap(); println!("Gift wrapped for {}", &gift);}// 4. Implement the Gift trait to the gift structsimpl fmt::Display for KidsGift { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}", self.name) }}impl Gift for KidsGift { fn wrap(&mut self) { self.is_wrapped = true }}impl fmt::Display for ElvesGift { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}", self.name) }}impl Gift for ElvesGift { fn wrap(&mut self) { self.is_wrapped = true }}impl fmt::Display for ReindeerGift { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}", self.name) }}impl Gift for ReindeerGift { fn wrap(&mut self) { self.is_wrapped = true }}pub fn main() { let mut kids_gift = KidsGift { name: "toy car".to_string(), is_wrapped: false, }; let mut elves_gift = ElvesGift { name: "vertical monitor".to_string(), is_wrapped: false, }; let mut reindeer_gift = ReindeerGift { name: "carrot".to_string(), is_wrapped: false, }; prepare_gift(&mut kids_gift); prepare_gift(&mut elves_gift); prepare_gift(&mut reindeer_gift);}
pagyeman
use std::fmt;// 1. Add the `is_wrapped` field to the gift structspub struct KidsGift { pub name: String, pub is_wrapped: bool,}pub struct ElvesGift { pub name: String, pub is_wrapped: bool,}pub struct ReindeerGift { pub name: String, pub is_wrapped: bool,}pub trait Gift // 2. Finish the trait definition //{ fn wrap(&mut self);}// 3. Update the function signaturepub fn prepare_gift<T: fmt::Display + Gift>(gift: &mut T) { println!("Preparing gift for {}", &gift); gift.wrap(); println!("Gift wrapped for {}", &gift);}// 4. Implement the Gift trait to the gift structsimpl fmt::Display for KidsGift { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}", self.name) }}impl Gift for KidsGift { fn wrap(&mut self) { self.is_wrapped = true }}impl fmt::Display for ElvesGift { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}", self.name) }}impl Gift for ElvesGift { fn wrap(&mut self) { self.is_wrapped = true }}impl fmt::Display for ReindeerGift { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}", self.name) }}impl Gift for ReindeerGift { fn wrap(&mut self) { self.is_wrapped = true }}pub fn main() { let mut kids_gift = KidsGift { name: "toy car".to_string(), is_wrapped: false, }; let mut elves_gift = ElvesGift { name: "vertical monitor".to_string(), is_wrapped: false, }; let mut reindeer_gift = ReindeerGift { name: "carrot".to_string(), is_wrapped: false, }; prepare_gift(&mut kids_gift); prepare_gift(&mut elves_gift); prepare_gift(&mut reindeer_gift);}
wamimi
use std::fmt;// 1. Add the `is_wrapped` field to the gift structspub struct KidsGift { pub name: String, pub is_wrapped: bool,}pub struct ElvesGift { pub name: String, pub is_wrapped: bool,}pub struct ReindeerGift { pub name: String, pub is_wrapped: bool,}pub trait Gift { fn wrap(&mut self);} // 2. Finish the trait definition //// 3. Update the function signaturepub fn prepare_gift<T: fmt::Display + Gift>(gift: &mut T) { println!("Preparing gift for {}", &gift); gift.wrap(); println!("Gift wrapped for {}", &gift);}// 4. Implement the Gift trait to the gift structsimpl Gift for KidsGift { fn wrap(&mut self) { self.is_wrapped = true; }}impl Gift for ElvesGift { fn wrap(&mut self) { self.is_wrapped = true; }}impl Gift for ReindeerGift { fn wrap(&mut self) { self.is_wrapped = true; }}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 mut kids_gift = KidsGift { name: "toy car".to_string(), is_wrapped: false, }; let mut elves_gift = ElvesGift { name: "vertical monitor".to_string(), is_wrapped: false, }; let mut reindeer_gift = ReindeerGift { name: "carrot".to_string(), is_wrapped: false, }; prepare_gift(&mut kids_gift); prepare_gift(&mut elves_gift); prepare_gift(&mut reindeer_gift);}
arm01846
use std::fmt;// 1. Add the `is_wrapped` field to the gift structspub struct KidsGift { pub name: String, pub is_wrapped: bool,}pub struct ElvesGift { pub name: String, pub is_wrapped: bool,}pub struct ReindeerGift { pub name: String, pub is_wrapped: bool,}pub trait Gift // 2. Finish the trait definition //{ fn wrap(&mut self);}// 3. Update the function signaturepub fn prepare_gift<T: fmt::Display + Gift>(gift: &mut T) { println!("Preparing gift for {}", &gift); gift.wrap(); println!("Gift wrapped for {}", &gift);}// 4. Implement the Gift trait to the gift structsimpl Gift for KidsGift { fn wrap(&mut self) { self.is_wrapped = true; }}impl Gift for ElvesGift { fn wrap(&mut self) { self.is_wrapped = true; }}impl Gift for ReindeerGift { fn wrap(&mut self) { self.is_wrapped = true; }}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 mut kids_gift = KidsGift { name: "toy car".to_string(), is_wrapped: false, }; let mut elves_gift = ElvesGift { name: "vertical monitor".to_string(), is_wrapped: false, }; let mut reindeer_gift = ReindeerGift { name: "carrot".to_string(), is_wrapped: false, }; prepare_gift(&mut kids_gift); prepare_gift(&mut elves_gift); prepare_gift(&mut reindeer_gift);}
titoeb
use std::fmt;// 1. Add the `is_wrapped` field to the gift structspub struct KidsGift { pub name: String, pub is_wrapped: bool,}pub struct ElvesGift { pub name: String, pub is_wrapped: bool,}pub struct ReindeerGift { pub name: String, pub is_wrapped: bool,}pub trait Gift // 2. Finish the trait definition //{ fn wrap(&mut self);}impl Gift for KidsGift { fn wrap(&mut self) { self.is_wrapped = true; }}impl Gift for ElvesGift { fn wrap(&mut self) { self.is_wrapped = true; }}impl Gift for ReindeerGift { fn wrap(&mut self) { self.is_wrapped = true; }}// 3. Update the function signaturepub fn prepare_gift<T: fmt::Display + Gift>(gift: &mut T) { println!("Preparing gift for {}", &gift); gift.wrap(); println!("Gift wrapped for {}", &gift);}// 4. Implement the Gift trait to the gift structsimpl 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 mut kids_gift = KidsGift { name: "toy car".to_string(), is_wrapped: false, }; let mut elves_gift = ElvesGift { name: "vertical monitor".to_string(), is_wrapped: false, }; let mut reindeer_gift = ReindeerGift { name: "carrot".to_string(), is_wrapped: false, }; prepare_gift(&mut kids_gift); prepare_gift(&mut elves_gift); prepare_gift(&mut reindeer_gift);}
gmvar
use std::fmt;// 1. Add the `is_wrapped` field to the gift structspub struct KidsGift { pub name: String, pub is_wrapped: bool,}pub struct ElvesGift { pub name: String, pub is_wrapped: bool,}pub struct ReindeerGift { pub name: String, pub is_wrapped: bool,}// 2. Finish the trait definition //pub trait Gift { fn wrap(&mut self);}// 4. Implement the Gift trait to the gift structsimpl Gift for KidsGift { fn wrap(&mut self) { self.is_wrapped = true; }}impl Gift for ElvesGift { fn wrap(&mut self) { self.is_wrapped = true; }}impl Gift for ReindeerGift { fn wrap(&mut self) { self.is_wrapped = true; }}// 3. Update the function signaturepub fn prepare_gift<T: fmt::Display + Gift>(gift: &mut T) { println!("Preparing gift for {}", &gift); gift.wrap(); println!("Gift wrapped for {}", &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 mut kids_gift = KidsGift { name: "toy car".to_string(), is_wrapped: false, }; let mut elves_gift = ElvesGift { name: "vertical monitor".to_string(), is_wrapped: false, }; let mut reindeer_gift = ReindeerGift { name: "carrot".to_string(), is_wrapped: false, }; prepare_gift(&mut kids_gift); prepare_gift(&mut elves_gift); prepare_gift(&mut reindeer_gift);}
tamanishi
use std::fmt;// 1. Add the `is_wrapped` field to the gift structspub struct KidsGift { pub name: String, pub is_wrapped: bool,}pub struct ElvesGift { pub name: String, pub is_wrapped: bool,}pub struct ReindeerGift { pub name: String, pub is_wrapped: bool,}// 2. Finish the trait definition //pub trait Gift { fn wrap(&mut self);}// 3. Update the function signaturepub fn prepare_gift<T: fmt::Display + Gift>(gift: &mut T) { println!("Preparing gift for {}", &gift); gift.wrap(); println!("Gift wrapped for {}", &gift);}// 4. Implement the Gift trait to the gift structsimpl Gift for KidsGift { fn wrap(&mut self) { self.is_wrapped = true; }}impl Gift for ElvesGift { fn wrap(&mut self) { self.is_wrapped = true; }}impl Gift for ReindeerGift { fn wrap(&mut self) { self.is_wrapped = true; }}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 mut kids_gift = KidsGift { name: "toy car".to_string(), is_wrapped: false, }; let mut elves_gift = ElvesGift { name: "vertical monitor".to_string(), is_wrapped: false, }; let mut reindeer_gift = ReindeerGift { name: "carrot".to_string(), is_wrapped: false, }; prepare_gift(&mut kids_gift); prepare_gift(&mut elves_gift); prepare_gift(&mut reindeer_gift);}
Nismirno
use std::fmt;// 1. Add the `is_wrapped` field to the gift structspub struct KidsGift { pub name: String, pub is_wrapped: bool,}pub struct ElvesGift { pub name: String, pub is_wrapped: bool,}pub struct ReindeerGift { pub name: String, pub is_wrapped: bool,}pub trait Gift { // 2. Finish the trait definition // fn wrap(&mut self);}// 3. Update the function signaturepub fn prepare_gift<T: fmt::Display + Gift>(gift: &mut T) { println!("Preparing gift for {}", &gift); gift.wrap(); println!("Gift wrapped for {}", &gift);}// 4. Implement the Gift trait to the gift structsimpl Gift for KidsGift { fn wrap(&mut self) { self.is_wrapped = true; }}impl Gift for ElvesGift { fn wrap(&mut self) { self.is_wrapped = true; }}impl Gift for ReindeerGift { fn wrap(&mut self) { self.is_wrapped = true; }}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 mut kids_gift = KidsGift { name: "toy car".to_string(), is_wrapped: false, }; let mut elves_gift = ElvesGift { name: "vertical monitor".to_string(), is_wrapped: false, }; let mut reindeer_gift = ReindeerGift { name: "carrot".to_string(), is_wrapped: false, }; prepare_gift(&mut kids_gift); prepare_gift(&mut elves_gift); prepare_gift(&mut reindeer_gift);}
gsspdev
use std::fmt;// 1. Add the `is_wrapped` field to the gift structspub struct KidsGift { pub name: String, pub is_wrapped: bool,}pub struct ElvesGift { pub name: String, pub is_wrapped: bool,}pub struct ReindeerGift { pub name: String, pub is_wrapped: bool,}pub trait Gift { fn wrap(&mut self);} // 2. Finish the trait definition //// 3. Update the function signaturepub fn prepare_gift<T: fmt::Display + Gift>(gift: &mut T) { println!("Preparing gift for {}", &gift); gift.wrap(); println!("Gift wrapped for {}", &gift);}// 4. Implement the Gift trait to the gift structsimpl Gift for KidsGift { fn wrap(&mut self) { self.is_wrapped = true; }}impl Gift for ElvesGift { fn wrap(&mut self) { self.is_wrapped = true; }}impl Gift for ReindeerGift { fn wrap(&mut self) { self.is_wrapped = true; }}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 mut kids_gift = KidsGift { name: "toy car".to_string(), is_wrapped: false, }; let mut elves_gift = ElvesGift { name: "vertical monitor".to_string(), is_wrapped: false, }; let mut reindeer_gift = ReindeerGift { name: "carrot".to_string(), is_wrapped: false, }; prepare_gift(&mut kids_gift); prepare_gift(&mut elves_gift); prepare_gift(&mut reindeer_gift);}
stanisgo
use std::fmt;// 1. Add the `is_wrapped` field to the gift structspub struct KidsGift { pub name: String, pub is_wrapped: bool,}pub struct ElvesGift { pub name: String, pub is_wrapped: bool,}pub struct ReindeerGift { pub name: String, pub is_wrapped: bool,}pub trait Gift { fn wrap(&mut self);}pub fn prepare_gift<T: fmt::Display + Gift>(gift: &mut T) { println!("Preparing gift for {}", &gift); gift.wrap(); println!("Gift wrapped for {}", &gift);}impl Gift for KidsGift { fn wrap(&mut self) { self.is_wrapped = true; }}impl Gift for ElvesGift { fn wrap(&mut self) { self.is_wrapped = true; }}impl Gift for ReindeerGift { fn wrap(&mut self) { self.is_wrapped = true; }}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 mut kids_gift = KidsGift { name: "toy car".to_string(), is_wrapped: false, }; let mut elves_gift = ElvesGift { name: "vertical monitor".to_string(), is_wrapped: false, }; let mut reindeer_gift = ReindeerGift { name: "carrot".to_string(), is_wrapped: false, }; prepare_gift(&mut kids_gift); prepare_gift(&mut elves_gift); prepare_gift(&mut reindeer_gift);}
hafihaf123
use std::fmt;// 1. Add the `is_wrapped` field to the gift structspub struct KidsGift { pub name: String, pub is_wrapped: bool,}impl Gift for KidsGift { fn wrap(&mut self) { self.is_wrapped = true; }}pub struct ElvesGift { pub name: String, pub is_wrapped: bool,}impl Gift for ElvesGift { fn wrap(&mut self) { self.is_wrapped = true; }}pub struct ReindeerGift { pub name: String, pub is_wrapped: bool,}impl Gift for ReindeerGift { fn wrap(&mut self) { self.is_wrapped = true; }}pub trait Gift { // 2. Finish the trait definition // fn wrap(&mut self);}// 3. Update the function signaturepub fn prepare_gift<T: Gift + fmt::Display>(gift: &mut T) { println!("Preparing gift for {}", gift); gift.wrap(); println!("Gift wrapped for {}", gift);}// 4. Implement the Gift trait to the gift structsimpl 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 mut kids_gift = KidsGift { name: "toy car".to_string(), is_wrapped: false, }; let mut elves_gift = ElvesGift { name: "vertical monitor".to_string(), is_wrapped: false, }; let mut reindeer_gift = ReindeerGift { name: "carrot".to_string(), is_wrapped: false, }; prepare_gift(&mut kids_gift); prepare_gift(&mut elves_gift); prepare_gift(&mut reindeer_gift);}
Burnus
use std::fmt;pub struct KidsGift { pub name: String, pub is_wrapped: bool,}pub struct ElvesGift { pub name: String, pub is_wrapped: bool,}pub struct ReindeerGift { pub name: String, pub is_wrapped: bool,}pub trait Gift { fn wrap(&mut self) {}} pub fn prepare_gift<T: fmt::Display + Gift>(gift: &mut T) { println!("Preparing gift for {}", &gift); gift.wrap(); println!("Gift wrapped for {}", &gift);}impl fmt::Display for KidsGift { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}", self.name) }}impl Gift for KidsGift { fn wrap(&mut self) { self.is_wrapped = true; }}impl fmt::Display for ElvesGift { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}", self.name) }}impl Gift for ElvesGift { fn wrap(&mut self) { self.is_wrapped = true; }}impl fmt::Display for ReindeerGift { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}", self.name) }}impl Gift for ReindeerGift { fn wrap(&mut self) { self.is_wrapped = true; }}pub fn main() { let mut kids_gift = KidsGift { name: "toy car".to_string(), is_wrapped: false, }; let mut elves_gift = ElvesGift { name: "vertical monitor".to_string(), is_wrapped: false, }; let mut reindeer_gift = ReindeerGift { name: "carrot".to_string(), is_wrapped: false, }; prepare_gift(&mut kids_gift); prepare_gift(&mut elves_gift); prepare_gift(&mut reindeer_gift);}
vaclav0411
use std::fmt;// 1. Add the `is_wrapped` field to the gift structspub struct KidsGift { pub name: String, pub is_wrapped: bool,}pub struct ElvesGift { pub name: String, pub is_wrapped: bool,}pub struct ReindeerGift { pub name: String, pub is_wrapped: bool,}pub trait Gift { fn wrap(&mut self);}impl Gift for KidsGift { fn wrap(&mut self) { self.is_wrapped = true; }}impl Gift for ElvesGift { fn wrap(&mut self) { self.is_wrapped = true; }}impl Gift for ReindeerGift { fn wrap(&mut self) { self.is_wrapped = true; }}// 3. Update the function signaturepub fn prepare_gift<T: fmt::Display + Gift>(gift: &mut T) { println!("Preparing gift for {}", &gift); gift.wrap(); println!("Gift wrapped for {}", &gift);}// 4. Implement the Gift trait to the gift structsimpl 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 mut kids_gift = KidsGift { name: "toy car".to_string(), is_wrapped: false, }; let mut elves_gift = ElvesGift { name: "vertical monitor".to_string(), is_wrapped: false, }; let mut reindeer_gift = ReindeerGift { name: "carrot".to_string(), is_wrapped: false, }; prepare_gift(&mut kids_gift); prepare_gift(&mut elves_gift); prepare_gift(&mut reindeer_gift);}
joanne-cmd
use std::fmt;// 1. Add the `is_wrapped` field to the gift structspub struct KidsGift { pub name: String, pub is_wrapped: bool,}pub struct ElvesGift { pub name: String, pub is_wrapped: bool,}pub struct ReindeerGift { pub name: String, pub is_wrapped: bool,}pub trait Gift { fn wrap(&mut self);} // 2. Finish the trait definition //// 3. Update the function signaturepub fn prepare_gift<T: fmt::Display + Gift>(gift: &mut T) { println!("Preparing gift for {}", &gift); gift.wrap(); println!("Gift wrapped for {}", &gift);}// 4. Implement the Gift trait to the gift structsimpl Gift for KidsGift { fn wrap(&mut self) { self.is_wrapped = true; }}impl Gift for ElvesGift { fn wrap(&mut self) { self.is_wrapped = true; }}impl Gift for ReindeerGift { fn wrap(&mut self) { self.is_wrapped = true; }}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 mut kids_gift = KidsGift { name: "toy car".to_string(), is_wrapped: false, }; let mut elves_gift = ElvesGift { name: "vertical monitor".to_string(), is_wrapped: false, }; let mut reindeer_gift = ReindeerGift { name: "carrot".to_string(), is_wrapped: false, }; prepare_gift(&mut kids_gift); prepare_gift(&mut elves_gift); prepare_gift(&mut reindeer_gift);}
felipesaruhashi
use std::fmt;// 1. Add the `is_wrapped` field to the gift structspub struct KidsGift { pub name: String, pub is_wrapped:bool,}pub struct ElvesGift { pub name: String, pub is_wrapped:bool,}pub struct ReindeerGift { pub name: String, pub is_wrapped:bool,}// 2. Finish the trait definition //pub trait Gift { fn wrap(&mut self);}// 3. Update the function signaturepub fn prepare_gift<T: fmt::Display + Gift>(gift: &mut T) { println!("Preparing gift for {}", &gift); gift.wrap(); println!("Gift wrapped for {}", &gift);}// 4. Implement the Gift trait to the gift structsimpl Gift for KidsGift{ fn wrap(&mut self){ self.is_wrapped = true; }}impl Gift for ReindeerGift{ fn wrap(&mut self){ self.is_wrapped = true; }}impl Gift for ElvesGift{ fn wrap(&mut self){ self.is_wrapped = true; }}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 mut kids_gift = KidsGift { name: "toy car".to_string(), is_wrapped: false, }; let mut elves_gift = ElvesGift { name: "vertical monitor".to_string(), is_wrapped: false, }; let mut reindeer_gift = ReindeerGift { name: "carrot".to_string(), is_wrapped: false, }; prepare_gift(&mut kids_gift); prepare_gift(&mut elves_gift); prepare_gift(&mut reindeer_gift);}
KLcpb
use std::fmt;// 1. Add the `is_wrapped` field to the gift structspub struct KidsGift { pub name: String, pub is_wrapped:bool,}pub struct ElvesGift { pub name: String, pub is_wrapped:bool,}pub struct ReindeerGift { pub name: String, pub is_wrapped:bool,}pub trait Gift { fn wrap(&mut self);}// 2. Finish the trait definition //// 3. Update the function signaturepub fn prepare_gift<T: fmt::Display + Gift>(gift: &mut T) { println!("Preparing gift for {}", &gift); gift.wrap(); println!("Gift wrapped for {}", &gift);}// 4. Implement the Gift trait to the gift structsimpl Gift for KidsGift{ fn wrap(&mut self){ self.is_wrapped = true; }}impl Gift for ReindeerGift{ fn wrap(&mut self){ self.is_wrapped = true; }}impl Gift for ElvesGift{ fn wrap(&mut self){ self.is_wrapped = true; }}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 mut kids_gift = KidsGift { name: "toy car".to_string(), is_wrapped: false, }; let mut elves_gift = ElvesGift { name: "vertical monitor".to_string(), is_wrapped: false, }; let mut reindeer_gift = ReindeerGift { name: "carrot".to_string(), is_wrapped: false, }; prepare_gift(&mut kids_gift); prepare_gift(&mut elves_gift); prepare_gift(&mut reindeer_gift);}
joshvon44
use std::fmt;// 1. Add the `is_wrapped` field to the gift structspub struct KidsGift { pub name: String, pub is_wrapped: bool,}pub struct ElvesGift { pub name: String, pub is_wrapped: bool,}pub struct ReindeerGift { pub name: String, pub is_wrapped: bool,}pub trait Gift { fn wrap(&mut self);} // 2. Finish the trait definition //// 3. Update the function signaturepub fn prepare_gift<T: fmt::Display + Gift>(gift: &mut T) { println!("Preparing gift for {}", &gift); gift.wrap(); println!("Gift wrapped for {}", &gift);}// 4. Implement the Gift trait to the gift structsimpl Gift for KidsGift { fn wrap(&mut self) { self.is_wrapped = true; }}impl Gift for ElvesGift { fn wrap(&mut self) { self.is_wrapped = true; }}impl Gift for ReindeerGift { fn wrap(&mut self) { self.is_wrapped = true; }}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 mut kids_gift = KidsGift { name: "toy car".to_string(), is_wrapped: false, }; let mut elves_gift = ElvesGift { name: "vertical monitor".to_string(), is_wrapped: false, }; let mut reindeer_gift = ReindeerGift { name: "carrot".to_string(), is_wrapped: false, }; prepare_gift(&mut kids_gift); prepare_gift(&mut elves_gift); prepare_gift(&mut reindeer_gift);}
wishkus
use std::fmt;// 1. Add the `is_wrapped` field to the gift structspub struct KidsGift { pub name: String, pub is_wrapped: bool,}pub struct ElvesGift { pub name: String, pub is_wrapped: bool,}pub struct ReindeerGift { pub name: String, pub is_wrapped: bool,}pub trait Gift {// 2. Finish the trait definition // fn wrap(&mut self);}// 3. Update the function signaturepub fn prepare_gift<T: fmt::Display + Gift>(gift: &mut T) { println!("Preparing gift for {}", &gift); gift.wrap(); println!("Gift wrapped for {}", &gift);}// 4. Implement the Gift trait to the gift structsimpl fmt::Display for KidsGift { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}", self.name) }}impl Gift for KidsGift { fn wrap(&mut self) { self.is_wrapped = true }}impl fmt::Display for ElvesGift { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}", self.name) }}impl Gift for ElvesGift { fn wrap(&mut self) { self.is_wrapped = true }}impl fmt::Display for ReindeerGift { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}", self.name) }}impl Gift for ReindeerGift { fn wrap(&mut self) { self.is_wrapped = true }}pub fn main() { let mut kids_gift = KidsGift { name: "toy car".to_string(), is_wrapped: false, }; let mut elves_gift = ElvesGift { name: "vertical monitor".to_string(), is_wrapped: false, }; let mut reindeer_gift = ReindeerGift { name: "carrot".to_string(), is_wrapped: false, }; prepare_gift(&mut kids_gift); prepare_gift(&mut elves_gift); prepare_gift(&mut reindeer_gift);}
strachan
use std::fmt;// 1. Add the `is_wrapped` field to the gift structspub struct KidsGift { pub name: String, pub is_wrapped: bool}pub struct ElvesGift { pub name: String, pub is_wrapped: bool}pub struct ReindeerGift { pub name: String, pub is_wrapped: bool}pub trait Gift { fn wrap(&mut self);}impl Gift for KidsGift { fn wrap(&mut self) { self.is_wrapped = true; }}impl Gift for ElvesGift { fn wrap(&mut self) { self.is_wrapped = true; }}impl Gift for ReindeerGift { fn wrap(&mut self) { self.is_wrapped = true; }}// 3. Update the function signaturepub fn prepare_gift<T: fmt::Display + Gift>(gift: &mut T) { println!("Preparing gift for {}", &gift); gift.wrap(); println!("Gift wrapped for {}", &gift);}// 4. Implement the Gift trait to the gift structsimpl 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 mut kids_gift = KidsGift { name: "toy car".to_string(), is_wrapped: false, }; let mut elves_gift = ElvesGift { name: "vertical monitor".to_string(), is_wrapped: false, }; let mut reindeer_gift = ReindeerGift { name: "carrot".to_string(), is_wrapped: false, }; prepare_gift(&mut kids_gift); prepare_gift(&mut elves_gift); prepare_gift(&mut reindeer_gift);}
chriswmann
use std::fmt;// 1. Add the `is_wrapped` field to the gift structspub struct KidsGift { pub name: String, pub is_wrapped: bool,}pub struct ElvesGift { pub name: String, pub is_wrapped: bool,}pub struct ReindeerGift { pub name: String, pub is_wrapped: bool,}pub trait Gift // 2. Finish the trait definition //{ fn wrap(&mut self) {}}// 3. Update the function signaturepub fn prepare_gift<G: fmt::Display + Gift>(gift: &mut G) { println!("Preparing gift for {}", &gift); gift.wrap(); println!("Gift wrapped for {}", &gift);}// 4. Implement the Gift trait to the gift structsimpl 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) }}impl Gift for KidsGift { fn wrap(&mut self) { self.is_wrapped = true; }}impl Gift for ElvesGift { fn wrap(&mut self) { self.is_wrapped = true; }}impl Gift for ReindeerGift { fn wrap(&mut self) { self.is_wrapped = true; }}pub fn main() { let mut kids_gift = KidsGift { name: "toy car".to_string(), is_wrapped: false, }; let mut elves_gift = ElvesGift { name: "vertical monitor".to_string(), is_wrapped: false, }; let mut reindeer_gift = ReindeerGift { name: "carrot".to_string(), is_wrapped: false, }; prepare_gift(&mut kids_gift); prepare_gift(&mut elves_gift); prepare_gift(&mut reindeer_gift);}
lulingar
use std::fmt;// 1. Add the `is_wrapped` field to the gift structspub struct KidsGift { pub name: String, pub is_wrapped: bool,}pub struct ElvesGift { pub name: String, pub is_wrapped: bool,}pub struct ReindeerGift { pub name: String, pub is_wrapped: bool,}pub trait Gift {// 2. Finish the trait definition // fn wrap(&mut self);}// 3. Update the function signaturepub fn prepare_gift<T: Gift + fmt::Display>(gift: &mut T) { println!("Preparing gift for {}", gift); gift.wrap(); println!("Gift wrapped for {}", gift);}// 4. Implement the Gift trait to the gift structsimpl fmt::Display for KidsGift { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}", self.name) }}impl Gift for KidsGift { fn wrap(&mut self) { self.is_wrapped = true; }}impl fmt::Display for ElvesGift { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}", self.name) }}impl Gift for ElvesGift { fn wrap(&mut self) { self.is_wrapped = true; }}impl fmt::Display for ReindeerGift { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}", self.name) }}impl Gift for ReindeerGift { fn wrap(&mut self) { self.is_wrapped = true; }}pub fn main() { let mut kids_gift = KidsGift { name: "toy car".to_string(), is_wrapped: false, }; let mut elves_gift = ElvesGift { name: "vertical monitor".to_string(), is_wrapped: false, }; let mut reindeer_gift = ReindeerGift { name: "carrot".to_string(), is_wrapped: false, }; prepare_gift(&mut kids_gift); prepare_gift(&mut elves_gift); prepare_gift(&mut reindeer_gift);}
kanakshilledar
use std::fmt;pub struct KidsGift { pub name: String, pub is_wrapped: bool,}pub struct ElvesGift { pub name: String, pub is_wrapped: bool,}pub struct ReindeerGift { pub name: String, pub is_wrapped: bool,}pub trait Gift { fn wrap(&mut self);}impl Gift for KidsGift { fn wrap(&mut self) -> () { self.is_wrapped = true; }}impl Gift for ElvesGift { fn wrap(&mut self) -> () { self.is_wrapped = true; }}impl Gift for ReindeerGift { fn wrap(&mut self) -> () { self.is_wrapped = true; }}pub fn prepare_gift<T: fmt::Display + Gift>(gift: &mut T) { println!("Preparing gift for {}", &gift); gift.wrap(); println!("Gift wrapped for {}", &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 mut kids_gift = KidsGift { name: "toy car".to_string(), is_wrapped: false, }; let mut elves_gift = ElvesGift { name: "vertical monitor".to_string(), is_wrapped: false, }; let mut reindeer_gift = ReindeerGift { name: "carrot".to_string(), is_wrapped: false, }; prepare_gift(&mut kids_gift); prepare_gift(&mut elves_gift); prepare_gift(&mut reindeer_gift);}
Stephan-Lindner
use std::fmt;pub struct KidsGift { pub name: String, pub is_wrapped: bool,}pub struct ElvesGift { pub name: String, pub is_wrapped: bool,}pub struct ReindeerGift { pub name: String, pub is_wrapped: bool,}pub trait Gift { fn wrap(&mut self);}impl Gift for KidsGift { fn wrap(&mut self) -> () { self.is_wrapped = true; }}impl Gift for ElvesGift { fn wrap(&mut self) -> () { self.is_wrapped = true; }}impl Gift for ReindeerGift { fn wrap(&mut self) -> () { self.is_wrapped = true; }}pub fn prepare_gift<T: fmt::Display + Gift>(gift: &mut T) { println!("Preparing gift for {}", &gift); gift.wrap(); println!("Gift wrapped for {}", &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 mut kids_gift = KidsGift { name: "toy car".to_string(), is_wrapped: false, }; let mut elves_gift = ElvesGift { name: "vertical monitor".to_string(), is_wrapped: false, }; let mut reindeer_gift = ReindeerGift { name: "carrot".to_string(), is_wrapped: false, }; prepare_gift(&mut kids_gift); prepare_gift(&mut elves_gift); prepare_gift(&mut reindeer_gift);}
martynovs
use std::fmt;// 1. Add the `is_wrapped` field to the gift structspub struct KidsGift { pub name: String, pub is_wrapped: bool,}pub struct ElvesGift { pub name: String, pub is_wrapped: bool,}pub struct ReindeerGift { pub name: String, pub is_wrapped: bool,}pub trait Gift { fn wrap(&mut self);}impl Gift for KidsGift { fn wrap(&mut self) { self.is_wrapped = true; }}impl Gift for ElvesGift { fn wrap(&mut self) { self.is_wrapped = true; }}impl Gift for ReindeerGift { fn wrap(&mut self) { self.is_wrapped = true; }}// 3. Update the function signaturepub fn prepare_gift<T: Gift + fmt::Display>(gift: &mut T) { println!("Preparing gift for {}", &gift); gift.wrap(); println!("Gift wrapped for {}", &gift);}// 4. Implement the Gift trait to the gift structsimpl 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 mut kids_gift = KidsGift { name: "toy car".to_string(), is_wrapped: false, }; let mut elves_gift = ElvesGift { name: "vertical monitor".to_string(), is_wrapped: false, }; let mut reindeer_gift = ReindeerGift { name: "carrot".to_string(), is_wrapped: false, }; prepare_gift(&mut kids_gift); prepare_gift(&mut elves_gift); prepare_gift(&mut reindeer_gift);}
GermanS
use std::fmt;// 1. Add the `is_wrapped` field to the gift structspub struct KidsGift { pub name: String, pub is_wrapped: bool,}pub struct ElvesGift { pub name: String, pub is_wrapped: bool,}pub struct ReindeerGift { pub name: String, pub is_wrapped: bool,}// 2. Finish the trait definition //pub trait Gift { fn wrap(&mut self);}// 3. Update the function signaturepub fn prepare_gift<T: fmt::Display + Gift>(gift: &mut T) { println!("Preparing gift for {}", &gift); gift.wrap(); println!("Gift wrapped for {}", &gift);}// 4. Implement the Gift trait to the gift structsimpl 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) }}impl Gift for KidsGift { fn wrap(&mut self) { self.is_wrapped = true; }}impl Gift for ElvesGift { fn wrap(&mut self) { self.is_wrapped = true; }}impl Gift for ReindeerGift { fn wrap(&mut self) { self.is_wrapped = true; }}pub fn main() { let mut kids_gift = KidsGift { name: "toy car".to_string(), is_wrapped: false, }; let mut elves_gift = ElvesGift { name: "vertical monitor".to_string(), is_wrapped: false, }; let mut reindeer_gift = ReindeerGift { name: "carrot".to_string(), is_wrapped: false, }; prepare_gift(&mut kids_gift); prepare_gift(&mut elves_gift); prepare_gift(&mut reindeer_gift);}
wlabranche
use std::fmt;// 1. Add the `is_wrapped` field to the gift structspub struct KidsGift { pub name: String, pub is_wrapped: bool,}pub struct ElvesGift { pub name: String, pub is_wrapped: bool,}pub struct ReindeerGift { pub name: String, pub is_wrapped: bool,}pub trait Gift { fn wrap(&mut self);} // 2. Finish the trait definition //impl Gift for KidsGift { fn wrap(&mut self) { self.is_wrapped = true; }}impl Gift for ElvesGift { fn wrap(&mut self) { self.is_wrapped = true; }}impl Gift for ReindeerGift { fn wrap(&mut self) { self.is_wrapped = true; }}// 3. Update the function signaturepub fn prepare_gift<T: fmt::Display + Gift>(gift: &mut T) { println!("Preparing gift for {}", &gift); gift.wrap(); println!("Gift wrapped for {}", &gift);}// 4. Implement the Gift trait to the gift structsimpl 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 mut kids_gift = KidsGift { name: "toy car".to_string(), is_wrapped: false, }; let mut elves_gift = ElvesGift { name: "vertical monitor".to_string(), is_wrapped: false, }; let mut reindeer_gift = ReindeerGift { name: "carrot".to_string(), is_wrapped: false, }; prepare_gift(&mut kids_gift); prepare_gift(&mut elves_gift); prepare_gift(&mut reindeer_gift);}
RedNapPanda
use std::fmt;// 1. Add the `is_wrapped` field to the gift structspub struct KidsGift { pub name: String, pub is_wrapped: bool,}pub struct ElvesGift { pub name: String, pub is_wrapped: bool,}pub struct ReindeerGift { pub name: String, pub is_wrapped: bool,}pub trait Gift { fn wrap(&mut self);}impl Gift for KidsGift { fn wrap(&mut self) { self.is_wrapped = true; }}impl Gift for ElvesGift { fn wrap(&mut self) { self.is_wrapped = true; }}impl Gift for ReindeerGift { fn wrap(&mut self) { self.is_wrapped = true; }}// 3. Update the function signaturepub fn prepare_gift<T: fmt::Display + Gift>(gift: &mut T) { println!("Preparing gift for {}", gift); gift.wrap(); println!("Gift wrapped for {}", gift);}// 4. Implement the Gift trait to the gift structsimpl 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 mut kids_gift = KidsGift { name: "toy car".to_string(), is_wrapped: false, }; let mut elves_gift = ElvesGift { name: "vertical monitor".to_string(), is_wrapped: false, }; let mut reindeer_gift = ReindeerGift { name: "carrot".to_string(), is_wrapped: false, }; prepare_gift(&mut kids_gift); prepare_gift(&mut elves_gift); prepare_gift(&mut reindeer_gift);}
wendko
use std::fmt;// 1. Add the `is_wrapped` field to the gift structspub struct KidsGift { pub name: String, pub is_wrapped: bool}pub struct ElvesGift { pub name: String, pub is_wrapped: bool}pub struct ReindeerGift { pub name: String, pub is_wrapped: bool}pub trait Gift { fn wrap(&mut self);}// 2. Finish the trait definition //// 3. Update the function signaturepub fn prepare_gift<T: fmt::Display + Gift>(gift: &mut T) { println!("Preparing gift for {}", &gift); gift.wrap(); println!("Gift wrapped for {}", &gift);}// 4. Implement the Gift trait to the gift structsimpl fmt::Display for KidsGift { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}", self.name) }}impl Gift for KidsGift { fn wrap(&mut self) -> () { self.is_wrapped = true; () }}impl fmt::Display for ElvesGift { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}", self.name) }}impl Gift for ElvesGift { fn wrap(&mut self) -> () { self.is_wrapped = true; () }}impl fmt::Display for ReindeerGift { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}", self.name) }}impl Gift for ReindeerGift { fn wrap(&mut self) -> () { self.is_wrapped = true; () }}pub fn main() { let mut kids_gift = KidsGift { name: "toy car".to_string(), is_wrapped: false, }; let mut elves_gift = ElvesGift { name: "vertical monitor".to_string(), is_wrapped: false, }; let mut reindeer_gift = ReindeerGift { name: "carrot".to_string(), is_wrapped: false, }; prepare_gift(&mut kids_gift); prepare_gift(&mut elves_gift); prepare_gift(&mut reindeer_gift);}
DominicD
use std::fmt;// 1. Add the `is_wrapped` field to the gift structspub struct KidsGift { pub name: String, pub is_wrapped: bool,}pub struct ElvesGift { pub name: String, pub is_wrapped: bool,}pub struct ReindeerGift { pub name: String, pub is_wrapped: bool,}pub trait Gift // 2. Finish the trait definition //{ fn wrap(&mut self);}impl Gift for KidsGift { fn wrap(&mut self) { self.is_wrapped = true }}impl Gift for ElvesGift { fn wrap(&mut self) { self.is_wrapped = true }}impl Gift for ReindeerGift { fn wrap(&mut self) { self.is_wrapped = true }}// 3. Update the function signaturepub fn prepare_gift<T: fmt::Display + Gift>(gift: &mut T) { println!("Preparing gift for {}", &gift); gift.wrap(); println!("Gift wrapped for {}", &gift);}// 4. Implement the Gift trait to the gift structsimpl 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 mut kids_gift = KidsGift { name: "toy car".to_string(), is_wrapped: false, }; let mut elves_gift = ElvesGift { name: "vertical monitor".to_string(), is_wrapped: false, }; let mut reindeer_gift = ReindeerGift { name: "carrot".to_string(), is_wrapped: false, }; prepare_gift(&mut kids_gift); prepare_gift(&mut elves_gift); prepare_gift(&mut reindeer_gift);}
jsdm13
use std::fmt;// 1. Add the `is_wrapped` field to the gift structspub struct KidsGift { pub name: String, pub is_wrapped: bool,}pub struct ElvesGift { pub name: String, pub is_wrapped: bool,}pub struct ReindeerGift { pub name: String, pub is_wrapped: bool,}pub trait Gift {// 2. Finish the trait definition // fn wrap(&mut self);}pub fn prepare_gift<T: fmt::Display + Gift>(gift: &mut T) { println!("Preparing gift for {}", &gift); gift.wrap(); println!("Gift wrapped for {}", &gift);}impl fmt::Display for KidsGift { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}", self.name) }}impl Gift for KidsGift { fn wrap(&mut self) { self.is_wrapped = true; }}impl fmt::Display for ElvesGift { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}", self.name) }}impl Gift for ElvesGift { fn wrap(&mut self) { self.is_wrapped = true; }}impl fmt::Display for ReindeerGift { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}", self.name) }}impl Gift for ReindeerGift { fn wrap(&mut self) { self.is_wrapped = true; }}pub fn main() { let mut kids_gift = KidsGift { name: "toy car".to_string(), is_wrapped: false, }; let mut elves_gift = ElvesGift { name: "vertical monitor".to_string(), is_wrapped: false, }; let mut reindeer_gift = ReindeerGift { name: "carrot".to_string(), is_wrapped: false, }; prepare_gift(&mut kids_gift); prepare_gift(&mut elves_gift); prepare_gift(&mut reindeer_gift);}
seilis
use std::fmt;// 1. Add the `is_wrapped` field to the gift structspub struct KidsGift { pub name: String, pub is_wrapped: bool,}pub struct ElvesGift { pub name: String, pub is_wrapped: bool,}pub struct ReindeerGift { pub name: String, pub is_wrapped: bool,}pub trait Gift { fn wrap(&mut self);}impl Gift for KidsGift { fn wrap(&mut self) { self.is_wrapped = true; }}impl Gift for ElvesGift { fn wrap(&mut self) { self.is_wrapped = true; }}impl Gift for ReindeerGift { fn wrap(&mut self) { self.is_wrapped = true; }}// 3. Update the function signaturepub fn prepare_gift<T>(gift: &mut T) where T: fmt::Display + Gift{ println!("Preparing gift for {}", &gift); gift.wrap(); println!("Gift wrapped for {}", &gift);}// 4. Implement the Gift trait to the gift structsimpl 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 mut kids_gift = KidsGift { name: "toy car".to_string(), is_wrapped: false, }; let mut elves_gift = ElvesGift { name: "vertical monitor".to_string(), is_wrapped: false, }; let mut reindeer_gift = ReindeerGift { name: "carrot".to_string(), is_wrapped: false, }; prepare_gift(&mut kids_gift); prepare_gift(&mut elves_gift); prepare_gift(&mut reindeer_gift);}