You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
25 lines
377 B
25 lines
377 B
4 years ago
|
// 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);
|
||
|
}
|