Julio Biason
4 years ago
1 changed files with 24 additions and 0 deletions
@ -0,0 +1,24 @@
|
||||
// Check if one can create a function that returns generics (instead of, say,
|
||||
// dyn).
|
||||
|
||||
trait SomeTrait {} |
||||
|
||||
// "marker" struct
|
||||
#[derive(Debug)] |
||||
struct SomeStruct { |
||||
field: u8, |
||||
} |
||||
|
||||
impl SomeTrait for SomeStruct {} |
||||
|
||||
fn gen_function<T>() -> T |
||||
where |
||||
T: SomeTrait, |
||||
{ |
||||
SomeStruct { field: 10 } |
||||
} |
||||
|
||||
fn main() { |
||||
let result = gen_function(); |
||||
println!("{:?}", result); |
||||
} |
Loading…
Reference in new issue