코딩Coding/Rust용어
Rust용어_impl Trait for returning complex type with ease.
내인생PLUS
2020. 9. 20. 11:49
728x90
impl Trait for returning complex types with ease - The Edition Guide
impl Trait is the new way to specify unnamed but concrete types that implement a specific trait. There are two places you can put it: argument position, and return position. trait Trait {} // argument position fn foo(arg: impl Trait) { } // return position
doc.rust-lang.org
Ex)
https://doc.rust-lang.org/rust-by-example/trait/impl_trait.html
impl Trait - Rust By Example
If your function returns a type that implements MyTrait, you can write its return type as -> impl MyTrait. This can help simplify your type signatures quite a lot! use std::iter; use std::vec::IntoIter; // This function combines two `Vec ` and returns an i
doc.rust-lang.org
반응형