Below code compiles and works fine:
use std::fmt::Display; fn display(x: &str) { println!("{}", x); } fn main() { let s: &str = "hi there"; display(s); }
However, if you change the display function to
fn display(x: &Display)
It produces the following error:
src/main.rs:9:13: 9:14 error: the trait `core::marker::Sized` is not implemented for the type `str` [E0277] src/main.rs:9 display(s);
Changing display(s) to display(&s) , it works again.
What's going on here? Obviously, the type is &str , but when &Display is an input argument, it does not recognize it.
Note: &34 also works fine as an argument. Is it because display actually implemented for &str , not str ?
source share