v2 / vlib / v / tests / generics / generic_struct_init_ptr_test.v
27 lines · 22 sloc · 500 bytes · 6488041a749df9762348d019c4223908c476f2e2
Raw
1module main
2
3pub enum AssetGetStatus {
4 ok
5 error
6}
7
8struct Sound {}
9
10struct Asset {}
11
12pub fn get[T]() (T, AssetGetStatus) {
13 $if T is Sound {
14 return Sound{}, AssetGetStatus.ok
15 } $else $if T is &Asset {
16 return &Asset{}, AssetGetStatus.ok
17 } $else {
18 $compile_error('get[T]: only retreival of Sound and &Asset is currently supported')
19 }
20 // Should not could be reached:
21 return T{}, AssetGetStatus.error
22}
23
24fn test_main() {
25 asset, status := get[&Asset]()
26 assert status == AssetGetStatus.ok
27}
28