B. Incorrect macro usage, should use {} instead of {:?}.
C. Function should return a value, missing return type.
D. No error, code compiles and runs fine.
Solution
Step 1: Understand the use of {:?} in println!
The {:?} format specifier requires the type to implement the Debug trait.
Step 2: Check function signature
The function print_debug has no trait bound on T, so the compiler cannot guarantee T implements Debug.
Final Answer:
Missing trait bound T: Debug for value. -> Option A
Quick Check:
Using {:?} requires T: Debug trait bound [OK]
Hint: Add trait bound when using {:?} formatting [OK]
Common Mistakes:
Forgetting to add T: Debug bound
Using {:?} without Debug trait
Assuming all types implement Debug by default
5. You want to write a generic function that accepts any type T which implements both Clone and Debug traits. Which is the correct way to write the function signature?
hard
A. fn process(value: T) {}
B. fn process(value: T) {}
C. fn process<T>(value: T) where T: Clone + Debug {}
D. }{ )T :eulav(>gubeD + enolC :T
Solution
Step 1: Understand trait bounds syntax
You can specify multiple trait bounds using either T: Trait1 + Trait2 or a where clause like where T: Trait1 + Trait2.
Step 2: Analyze options
fn process(value: T) {} uses T: Clone + Debug which is correct. fn process(value: T) {} incorrectly separates traits with a comma. fn process<T>(value: T) where T: Clone + Debug {} uses a valid where clause. fn process(value: T) {} states "Both A and C are correct" which is not an option here, so only C is correct.
Final Answer:
fn process<T>(value: T) where T: Clone + Debug {} -> Option C
Quick Check:
Multiple trait bounds can be combined with + or where clause [OK]
Hint: Use + or where clause to combine trait bounds [OK]
Common Mistakes:
Separating trait bounds with commas instead of +
Confusing where clause syntax
Using only one trait bound when multiple needed
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.