Rust

[Rust lang] 91. about impl trait

밍글링글링 2023. 3. 30.
728x90
use std::fmt::Display;

fn generic_function<T: Display>(input: T) {
    println!("{input}");
}

type MyString = impl Display;

fn impl_function(input: impl Display) {
    println!("{input}");
}
fn returns_a_closure() -> impl Fn(i32) {
    |x| println!("{x}")
}

fn main() {
    let my_number = 9;
    let my_closure = returns_a_closure();
    my_closure(my_number);

    generic_function(8);
}
728x90

'Rust' 카테고리의 다른 글

[Rust lang] 93. deref trait  (0) 2023.03.30
[Rust lang] 92. attribute part  (0) 2023.03.30
[Rust lang] 90. fn mut fnonce  (0) 2023.03.30
[Rust lang] 89. function pointers  (0) 2023.03.30
[Rust lang] 88. three types of generics  (0) 2023.03.30

댓글