728x90
use std::fmt::Display;
fn print<T: Display>(input: T) {
println!("Hi, I'm a {input}");
}
fn print_2(input: impl Display) {
println!("Hi, I'm a {input}");
}
fn print_3(input: Box<dyn Display>) {
println!("Hi, I'm a {input}");
}
fn main() {
print_2(8);
print_3(Box::new(String::from("I am a String")));
}
728x90
'Rust' 카테고리의 다른 글
[Rust lang] 90. fn mut fnonce (0) | 2023.03.30 |
---|---|
[Rust lang] 89. function pointers (0) | 2023.03.30 |
[Rust lang] 87. trait objects, box (0) | 2023.03.30 |
[Rust lang] 86. box (0) | 2023.03.30 |
[Rust lang] 85. clippy (0) | 2023.03.30 |
댓글