mirror of
https://github.com/google/comprehensive-rust.git
synced 2025-04-25 16:54:32 +02:00
436 B
436 B
impl Trait
Similar to trait bounds, an impl Trait
syntax can be used in function
arguments and return values:
use std::fmt::Display;
fn get_x(name: impl Display) -> impl Display {
format!("Hello {name}")
}
fn main() {
let x = get_x("foo");
println!("{x}");
}
impl Trait
cannot be used with the::<>
turbo fish syntax.impl Trait
allows you to work with types which you cannot name.