-
Notifications
You must be signed in to change notification settings - Fork 6
/
type-declarations.html
1708 lines (1543 loc) · 75.8 KB
/
type-declarations.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html lang="en" data-theme="dark">
<head>
<meta charset="UTF-8">
<meta content="width=device-width, initial-scale=1" name="viewport">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/codemirror/6.65.7/codemirror.min.css">
<link rel="stylesheet" href="assets/styles/v-docs.css">
<link rel="stylesheet" href="assets/styles/v-docs-cm-theme.css">
<title>V Documentation</title>
</head>
<body>
<header>
<div class="header-container">
<ul class="header-container-left-section">
<li class="sidebar-open-btn" role="button" aria-label="Open sidebar...">
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 -960 960 960">
<path d="M120-240v-80h720v80H120Zm0-200v-80h720v80H120Zm0-200v-80h720v80H120Z" fill="white" />
</svg>
</li>
</ul>
<div class="logo"></div>
<ul class="header-container-right-section">
<li>
<a href="https://github.com/vlang/docs/tree/generator" target="_blank">Source code</a>
</li>
<li class="js-change-theme__action change-theme" role="button" aria-label="Change theme...">
<svg class="theme-icon sun" width="30" height="30" viewBox="0 0 30 30" fill="none"
xmlns="http://www.w3.org/2000/svg">
<!-- <g clip-path="url(#clip0_4_47)"> -->
<path
d="M14.9854 1.92059C14.7382 1.92445 14.5026 2.02624 14.3304 2.20361C14.1581 2.38099 14.0633 2.61946 14.0667 2.86668V5.66668C14.0649 5.79036 14.0878 5.91315 14.1339 6.02792C14.18 6.14269 14.2485 6.24715 14.3353 6.33523C14.4222 6.42331 14.5256 6.49325 14.6398 6.54098C14.7539 6.58872 14.8763 6.61331 15 6.61331C15.1237 6.61331 15.2462 6.58872 15.3603 6.54098C15.4744 6.49325 15.5778 6.42331 15.6647 6.33523C15.7515 6.24715 15.82 6.14269 15.8661 6.02792C15.9122 5.91315 15.9351 5.79036 15.9333 5.66668V2.86668C15.935 2.74181 15.9117 2.61786 15.8646 2.50219C15.8176 2.38651 15.7478 2.28145 15.6594 2.19323C15.571 2.10501 15.4658 2.03542 15.35 1.98859C15.2343 1.94176 15.1103 1.91863 14.9854 1.92059ZM6.41042 5.47892C6.2249 5.47933 6.04372 5.53501 5.88999 5.63885C5.73626 5.7427 5.61696 5.89 5.54732 6.06195C5.47768 6.2339 5.46086 6.4227 5.499 6.60425C5.53714 6.7858 5.62852 6.95187 5.76146 7.08126L7.74115 9.06095C7.82715 9.15052 7.93016 9.22204 8.04415 9.2713C8.15814 9.32056 8.28081 9.34659 8.40498 9.34785C8.52915 9.34912 8.65232 9.32559 8.76728 9.27865C8.88225 9.23172 8.98669 9.16231 9.0745 9.07451C9.1623 8.9867 9.23171 8.88226 9.27864 8.76729C9.32558 8.65233 9.34911 8.52915 9.34784 8.40498C9.34658 8.28081 9.32056 8.15814 9.27129 8.04416C9.22203 7.93017 9.15051 7.82716 9.06094 7.74116L7.08125 5.76147C6.99406 5.67184 6.88975 5.60065 6.77451 5.55211C6.65928 5.50357 6.53546 5.47868 6.41042 5.47892V5.47892ZM23.5604 5.47892C23.3179 5.48614 23.0878 5.58748 22.9188 5.76147L20.9391 7.74116C20.8495 7.82716 20.778 7.93017 20.7287 8.04416C20.6795 8.15814 20.6534 8.28081 20.6522 8.40498C20.6509 8.52915 20.6744 8.65233 20.7214 8.76729C20.7683 8.88225 20.8377 8.9867 20.9255 9.0745C21.0133 9.16231 21.1178 9.23171 21.2327 9.27865C21.3477 9.32558 21.4709 9.34911 21.595 9.34785C21.7192 9.34659 21.8419 9.32056 21.9559 9.2713C22.0698 9.22203 22.1729 9.15052 22.2589 9.06095L24.2385 7.08126C24.3734 6.95016 24.4655 6.78138 24.5028 6.59703C24.5401 6.41268 24.5209 6.22136 24.4476 6.04814C24.3742 5.87493 24.2503 5.7279 24.092 5.62633C23.9337 5.52475 23.7484 5.47337 23.5604 5.47892ZM15 8.46668C13.2673 8.46668 11.6055 9.15501 10.3802 10.3802C9.155 11.6055 8.46667 13.2673 8.46667 15C8.46667 16.7328 9.155 18.3945 10.3802 19.6198C11.6055 20.845 13.2673 21.5333 15 21.5333C16.7328 21.5333 18.3945 20.845 19.6198 19.6198C20.845 18.3945 21.5333 16.7328 21.5333 15C21.5333 13.2673 20.845 11.6055 19.6198 10.3802C18.3945 9.15501 16.7328 8.46668 15 8.46668V8.46668ZM2.86667 14.0667C2.74299 14.0649 2.6202 14.0878 2.50543 14.1339C2.39066 14.18 2.2862 14.2485 2.19812 14.3353C2.11004 14.4222 2.0401 14.5257 1.99237 14.6398C1.94463 14.7539 1.92004 14.8763 1.92004 15C1.92004 15.1237 1.94463 15.2462 1.99237 15.3603C2.0401 15.4744 2.11004 15.5779 2.19812 15.6647C2.2862 15.7515 2.39066 15.82 2.50543 15.8661C2.6202 15.9122 2.74299 15.9351 2.86667 15.9333H5.66667C5.79035 15.9351 5.91314 15.9122 6.02791 15.8661C6.14268 15.82 6.24714 15.7515 6.33522 15.6647C6.4233 15.5779 6.49324 15.4744 6.54098 15.3603C6.58871 15.2462 6.6133 15.1237 6.6133 15C6.6133 14.8763 6.58871 14.7539 6.54098 14.6398C6.49324 14.5257 6.4233 14.4222 6.33522 14.3353C6.24714 14.2485 6.14268 14.18 6.02791 14.1339C5.91314 14.0878 5.79035 14.0649 5.66667 14.0667H2.86667ZM24.3333 14.0667C24.2097 14.0649 24.0869 14.0878 23.9721 14.1339C23.8573 14.18 23.7529 14.2485 23.6648 14.3353C23.5767 14.4222 23.5068 14.5257 23.459 14.6398C23.4113 14.7539 23.3867 14.8763 23.3867 15C23.3867 15.1237 23.4113 15.2462 23.459 15.3603C23.5068 15.4744 23.5767 15.5779 23.6648 15.6647C23.7529 15.7515 23.8573 15.82 23.9721 15.8661C24.0869 15.9122 24.2097 15.9351 24.3333 15.9333H27.1333C27.257 15.9351 27.3798 15.9122 27.4946 15.8661C27.6093 15.82 27.7138 15.7515 27.8019 15.6647C27.89 15.5779 27.9599 15.4744 28.0076 15.3603C28.0554 15.2462 28.08 15.1237 28.08 15C28.08 14.8763 28.0554 14.7539 28.0076 14.6398C27.9599 14.5257 27.89 14.4222 27.8019 14.3353C27.7138 14.2485 27.6093 14.18 27.4946 14.1339C27.3798 14.0878 27.257 14.0649 27.1333 14.0667H24.3333ZM8.38282 20.6565C8.14034 20.6637 7.9102 20.7651 7.74115 20.9391L5.76146 22.9188C5.67189 23.0048 5.60038 23.1078 5.55111 23.2218C5.50185 23.3357 5.47582 23.4584 5.47456 23.5826C5.4733 23.7068 5.49683 23.8299 5.54376 23.9449C5.5907 24.0599 5.6601 24.1643 5.74791 24.2521C5.83572 24.3399 5.94016 24.4093 6.05512 24.4563C6.17009 24.5032 6.29326 24.5267 6.41743 24.5255C6.5416 24.5242 6.66427 24.4982 6.77825 24.4489C6.89224 24.3996 6.99525 24.3281 7.08125 24.2386L9.06094 22.2589C9.19581 22.1278 9.28793 21.959 9.32522 21.7746C9.36252 21.5903 9.34325 21.399 9.26995 21.2257C9.19664 21.0525 9.07272 20.9055 8.91442 20.8039C8.75612 20.7024 8.57082 20.651 8.38282 20.6565ZM21.5898 20.6565C21.4042 20.6566 21.2227 20.712 21.0687 20.8157C20.9147 20.9194 20.7951 21.0667 20.7253 21.2387C20.6554 21.4107 20.6384 21.5997 20.6765 21.7814C20.7146 21.9631 20.806 22.1294 20.9391 22.2589L22.9188 24.2386C23.0048 24.3281 23.1078 24.3996 23.2218 24.4489C23.3357 24.4982 23.4584 24.5242 23.5826 24.5254C23.7067 24.5267 23.8299 24.5032 23.9449 24.4562C24.0598 24.4093 24.1643 24.3399 24.2521 24.2521C24.3399 24.1643 24.4093 24.0599 24.4562 23.9449C24.5032 23.8299 24.5267 23.7068 24.5254 23.5826C24.5242 23.4584 24.4982 23.3357 24.4489 23.2218C24.3996 23.1078 24.3281 23.0048 24.2385 22.9188L22.2589 20.9391C22.1719 20.8497 22.0679 20.7786 21.953 20.7301C21.8381 20.6815 21.7146 20.6565 21.5898 20.6565V20.6565ZM14.9854 23.3873C14.7382 23.3911 14.5026 23.4929 14.3304 23.6703C14.1581 23.8477 14.0633 24.0861 14.0667 24.3333V27.1333C14.0649 27.257 14.0878 27.3798 14.1339 27.4946C14.18 27.6094 14.2485 27.7138 14.3353 27.8019C14.4222 27.89 14.5256 27.9599 14.6398 28.0077C14.7539 28.0554 14.8763 28.08 15 28.08C15.1237 28.08 15.2462 28.0554 15.3603 28.0077C15.4744 27.9599 15.5778 27.89 15.6647 27.8019C15.7515 27.7138 15.82 27.6094 15.8661 27.4946C15.9122 27.3798 15.9351 27.257 15.9333 27.1333V24.3333C15.935 24.2085 15.9117 24.0845 15.8646 23.9689C15.8176 23.8532 15.7478 23.7481 15.6594 23.6599C15.571 23.5717 15.4658 23.5021 15.35 23.4553C15.2343 23.4084 15.1103 23.3853 14.9854 23.3873V23.3873Z"
fill="white" />
<!-- </g> -->
<defs>
<clipPath id="clip0_4_47">
<rect width="24" height="24" fill="white" transform="translate(1 1)" />
</clipPath>
</defs>
</svg>
<svg class="theme-icon moon" width="30" height="30" viewBox="0 0 30 30" fill="none"
xmlns="http://www.w3.org/2000/svg">
<path fill-rule="evenodd" clip-rule="evenodd"
d="M27.1371 20.5912C25.7519 21.0833 24.2605 21.3512 22.7065 21.3512C15.3985 21.3512 9.47424 15.4269 9.47424 8.11889C9.47424 6.10409 9.92454 4.19447 10.73 2.48517C5.60094 4.30725 1.92825 9.20347 1.92825 14.9575C1.92825 22.2655 7.85255 28.1898 15.1605 28.1898C20.4537 28.1898 25.021 25.0818 27.1371 20.5912Z"
fill="white" />
</svg>
</li>
</ul>
</div>
</header>
<div class="wrapper">
<aside id="sidebar-main">
<div class="sidebar-header">
<a href="index.html">
<img src="assets/images/logo.svg" alt="">
<span>Documentation</span>
</a>
<div class="sidebar-close-btn" role="button" aria-label="Close sidebar...">
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 -960 960 960">
<path
d="m256-200-56-56 224-224-224-224 56-56 224 224 224-224 56 56-224 224 224 224-56 56-224-224-224 224Z"
fill="white" />
</svg>
</div>
</div>
<div id="search-widget" class="sidebar-tool">
<!-- Search Input and Button -->
<input type="text" id="search-input" placeholder="Search">
<button id="search-button" role="button" aria-label="Perform search...">
<svg width="14" height="14" viewBox="0 0 20 20" aria-hidden="true">
<path d="M14.386 14.386l4.0877 4.0877-4.0877-4.0877c-2.9418 2.9419-7.7115 2.9419-10.6533 0-2.9419-2.9418-2.9419-7.7115 0-10.6533 2.9418-2.9419 7.7115-2.9419 10.6533 0 2.9419 2.9418 2.9419 7.7115 0 10.6533z" stroke="currentColor" fill="none" fill-rule="evenodd" stroke-linecap="round" stroke-linejoin="round"></path>
</svg>
</button>
<kbd id="search-kb-shortcut" class="kb-shortcut"></kbd>
</div>
<nav id="search-results" class="nav-list">
<div id="search-results-header">
<span>Search results...</span>
<div id="search-results-close" role="button" aria-label="Close search results..." title="Press ESC to close search results....">
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 -960 960 960">
<path d="m256-200-56-56 224-224-224-224 56-56 224 224 224-224 56 56-224 224 224 224-56 56-224-224-224 224Z" fill="white"></path>
</svg>
</div>
</div>
<div class="nav-contents">
<div class="nav-group" id="search-result-container">
</div>
</div>
</nav>
<nav id="topics" class="nav-list">
<div class="nav-contents">
<div class="nav-group">
<div class="nav-entry is-group-header">
<a class="nav-entry-link" href="introduction.html">Introduction</a>
</div>
<div class="nav-group-body">
</div>
</div>
<div class="nav-group">
<div class="nav-entry is-group-header">
<a class="nav-entry-link" href="installing-v-from-source.html">Installing V from source</a>
</div>
<div class="nav-group-body">
</div>
</div>
<div class="nav-group">
<div class="nav-entry is-group-header">
<a class="nav-entry-link" href="upgrading-v-to-latest-version.html">Upgrading V to latest version</a>
</div>
<div class="nav-group-body">
</div>
</div>
<div class="nav-group">
<div class="nav-entry is-group-header">
<a class="nav-entry-link" href="packaging-v-for-distribution.html">Packaging V for distribution</a>
</div>
<div class="nav-group-body">
</div>
</div>
<div class="nav-group">
<div class="nav-entry is-group-header">
<a class="nav-entry-link" href="getting-started.html">Getting started</a>
</div>
<div class="nav-group-body">
</div>
</div>
<div class="nav-group">
<div class="nav-entry is-group-header">
<a class="nav-entry-link" href="hello-world.html">Hello World</a>
</div>
<div class="nav-group-body">
</div>
</div>
<div class="nav-group">
<div class="nav-entry is-group-header">
<a class="nav-entry-link" href="running-a-project-folder-with-several-files.html">Running a project folder with several files</a>
</div>
<div class="nav-group-body">
</div>
</div>
<div class="nav-group">
<div class="nav-entry is-group-header">
<a class="nav-entry-link" href="comments.html">Comments</a>
</div>
<div class="nav-group-body">
</div>
</div>
<div class="nav-group">
<div class="nav-entry is-group-header">
<a class="nav-entry-link" href="functions.html">Functions</a>
</div>
<div class="nav-group-body">
<div class="nav-entry">
<a class="nav-entry-link" href="functions.html#hoisting"> Hoisting</a>
</div>
<div class="nav-entry">
<a class="nav-entry-link" href="functions.html#returning-multiple-values"> Returning multiple values</a>
</div>
</div>
</div>
<div class="nav-group">
<div class="nav-entry is-group-header">
<a class="nav-entry-link" href="symbol-visibility.html">Symbol visibility</a>
</div>
<div class="nav-group-body">
</div>
</div>
<div class="nav-group">
<div class="nav-entry is-group-header">
<a class="nav-entry-link" href="variables.html">Variables</a>
</div>
<div class="nav-group-body">
<div class="nav-entry">
<a class="nav-entry-link" href="variables.html#mutable-variables"> Mutable variables</a>
</div>
<div class="nav-entry">
<a class="nav-entry-link" href="variables.html#initialization-vs-assignment"> Initialization vs assignment</a>
</div>
<div class="nav-entry">
<a class="nav-entry-link" href="variables.html#warnings-and-declaration-errors"> Warnings and declaration errors</a>
</div>
</div>
</div>
<div class="nav-group">
<div class="nav-entry is-group-header">
<a class="nav-entry-link" href="v-types.html">V Types</a>
</div>
<div class="nav-group-body">
<div class="nav-entry">
<a class="nav-entry-link" href="v-types.html#primitive-types"> Primitive types</a>
</div>
<div class="nav-entry">
<a class="nav-entry-link" href="v-types.html#strings"> Strings</a>
</div>
<div class="nav-entry">
<a class="nav-entry-link" href="v-types.html#runes"> Runes</a>
</div>
<div class="nav-entry">
<a class="nav-entry-link" href="v-types.html#numbers"> Numbers</a>
</div>
<div class="nav-entry">
<a class="nav-entry-link" href="v-types.html#arrays"> Arrays</a>
</div>
<div class="nav-entry">
<a class="nav-entry-link" href="v-types.html#fixed-size-arrays"> Fixed size arrays</a>
</div>
<div class="nav-entry">
<a class="nav-entry-link" href="v-types.html#maps"> Maps</a>
</div>
<div class="nav-entry">
<a class="nav-entry-link" href="v-types.html#map-update-syntax"> Map update syntax</a>
</div>
</div>
</div>
<div class="nav-group">
<div class="nav-entry is-group-header">
<a class="nav-entry-link" href="module-imports.html">Module imports</a>
</div>
<div class="nav-group-body">
<div class="nav-entry">
<a class="nav-entry-link" href="module-imports.html#selective-imports"> Selective imports</a>
</div>
<div class="nav-entry">
<a class="nav-entry-link" href="module-imports.html#module-hierarchy"> Module hierarchy</a>
</div>
<div class="nav-entry">
<a class="nav-entry-link" href="module-imports.html#module-import-aliasing"> Module import aliasing</a>
</div>
</div>
</div>
<div class="nav-group">
<div class="nav-entry is-group-header">
<a class="nav-entry-link" href="statements-&-expressions.html">Statements & expressions</a>
</div>
<div class="nav-group-body">
<div class="nav-entry">
<a class="nav-entry-link" href="statements-&-expressions.html#if"> If</a>
</div>
<div class="nav-entry">
<a class="nav-entry-link" href="statements-&-expressions.html#match"> Match</a>
</div>
<div class="nav-entry">
<a class="nav-entry-link" href="statements-&-expressions.html#in-operator"> In operator</a>
</div>
<div class="nav-entry">
<a class="nav-entry-link" href="statements-&-expressions.html#for-loop"> For loop</a>
</div>
<div class="nav-entry">
<a class="nav-entry-link" href="statements-&-expressions.html#defer"> Defer</a>
</div>
<div class="nav-entry">
<a class="nav-entry-link" href="statements-&-expressions.html#goto"> Goto</a>
</div>
</div>
</div>
<div class="nav-group">
<div class="nav-entry is-group-header">
<a class="nav-entry-link" href="structs.html">Structs</a>
</div>
<div class="nav-group-body">
<div class="nav-entry">
<a class="nav-entry-link" href="structs.html#heap-structs"> Heap structs</a>
</div>
<div class="nav-entry">
<a class="nav-entry-link" href="structs.html#default-field-values"> Default field values</a>
</div>
<div class="nav-entry">
<a class="nav-entry-link" href="structs.html#required-fields"> Required fields</a>
</div>
<div class="nav-entry">
<a class="nav-entry-link" href="structs.html#short-struct-literal-syntax"> Short struct literal syntax</a>
</div>
<div class="nav-entry">
<a class="nav-entry-link" href="structs.html#struct-update-syntax"> Struct update syntax</a>
</div>
<div class="nav-entry">
<a class="nav-entry-link" href="structs.html#trailing-struct-literal-arguments"> Trailing struct literal arguments</a>
</div>
<div class="nav-entry">
<a class="nav-entry-link" href="structs.html#access-modifiers"> Access modifiers</a>
</div>
<div class="nav-entry">
<a class="nav-entry-link" href="structs.html#anonymous-structs"> Anonymous structs</a>
</div>
<div class="nav-entry">
<a class="nav-entry-link" href="structs.html#static-type-methods"> Static type methods</a>
</div>
<div class="nav-entry">
<a class="nav-entry-link" href="structs.html#noinit-structs"> [noinit] structs</a>
</div>
<div class="nav-entry">
<a class="nav-entry-link" href="structs.html#methods"> Methods</a>
</div>
<div class="nav-entry">
<a class="nav-entry-link" href="structs.html#embedded-structs"> Embedded structs</a>
</div>
</div>
</div>
<div class="nav-group">
<div class="nav-entry is-group-header">
<a class="nav-entry-link" href="unions.html">Unions</a>
</div>
<div class="nav-group-body">
</div>
</div>
<div class="nav-group">
<div class="nav-entry is-group-header">
<a class="nav-entry-link" href="functions-2.html">Functions 2</a>
</div>
<div class="nav-group-body">
<div class="nav-entry">
<a class="nav-entry-link" href="functions-2.html#immutable-function-args-by-default"> Immutable function args by default</a>
</div>
<div class="nav-entry">
<a class="nav-entry-link" href="functions-2.html#mutable-arguments"> Mutable arguments</a>
</div>
<div class="nav-entry">
<a class="nav-entry-link" href="functions-2.html#variable-number-of-arguments"> Variable number of arguments</a>
</div>
<div class="nav-entry">
<a class="nav-entry-link" href="functions-2.html#anonymous-&-higher-order-functions"> Anonymous & higher order functions</a>
</div>
<div class="nav-entry">
<a class="nav-entry-link" href="functions-2.html#closures"> Closures</a>
</div>
<div class="nav-entry">
<a class="nav-entry-link" href="functions-2.html#parameter-evaluation-order"> Parameter evaluation order</a>
</div>
</div>
</div>
<div class="nav-group">
<div class="nav-entry is-group-header">
<a class="nav-entry-link" href="references.html">References</a>
</div>
<div class="nav-group-body">
</div>
</div>
<div class="nav-group">
<div class="nav-entry is-group-header">
<a class="nav-entry-link" href="constants.html">Constants</a>
</div>
<div class="nav-group-body">
<div class="nav-entry">
<a class="nav-entry-link" href="constants.html#required-module-prefix"> Required module prefix</a>
</div>
</div>
</div>
<div class="nav-group">
<div class="nav-entry is-group-header">
<a class="nav-entry-link" href="builtin-functions.html">Builtin functions</a>
</div>
<div class="nav-group-body">
<div class="nav-entry">
<a class="nav-entry-link" href="builtin-functions.html#println"> println</a>
</div>
<div class="nav-entry">
<a class="nav-entry-link" href="builtin-functions.html#printing-custom-types"> Printing custom types</a>
</div>
<div class="nav-entry">
<a class="nav-entry-link" href="builtin-functions.html#dumping-expressions-at-runtime"> Dumping expressions at runtime</a>
</div>
</div>
</div>
<div class="nav-group">
<div class="nav-entry is-group-header">
<a class="nav-entry-link" href="modules.html">Modules</a>
</div>
<div class="nav-group-body">
<div class="nav-entry">
<a class="nav-entry-link" href="modules.html#create-modules"> Create modules</a>
</div>
<div class="nav-entry">
<a class="nav-entry-link" href="modules.html#special-considerations-for-project-folders"> Special considerations for project folders</a>
</div>
<div class="nav-entry">
<a class="nav-entry-link" href="modules.html#init-functions"> init functions</a>
</div>
<div class="nav-entry">
<a class="nav-entry-link" href="modules.html#cleanup-functions"> cleanup functions</a>
</div>
</div>
</div>
<div class="nav-group">
<div class="nav-entry is-group-header is-selected">
<a class="nav-entry-link" href="type-declarations.html">Type Declarations</a>
</div>
<div class="nav-group-body">
<div class="nav-entry">
<a class="nav-entry-link" href="type-declarations.html#type-aliases"> Type aliases</a>
</div>
<div class="nav-entry">
<a class="nav-entry-link" href="type-declarations.html#enums"> Enums</a>
</div>
<div class="nav-entry">
<a class="nav-entry-link" href="type-declarations.html#function-types"> Function Types</a>
</div>
<div class="nav-entry">
<a class="nav-entry-link" href="type-declarations.html#interfaces"> Interfaces</a>
</div>
<div class="nav-entry">
<a class="nav-entry-link" href="type-declarations.html#sum-types"> Sum types</a>
</div>
<div class="nav-entry">
<a class="nav-entry-link" href="type-declarations.html#optionresult-types-and-error-handling"> Option/Result types and error handling</a>
</div>
<div class="nav-entry">
<a class="nav-entry-link" href="type-declarations.html#custom-error-types"> Custom error types</a>
</div>
<div class="nav-entry">
<a class="nav-entry-link" href="type-declarations.html#generics"> Generics</a>
</div>
</div>
</div>
<div class="nav-group">
<div class="nav-entry is-group-header">
<a class="nav-entry-link" href="concurrency.html">Concurrency</a>
</div>
<div class="nav-group-body">
<div class="nav-entry">
<a class="nav-entry-link" href="concurrency.html#spawning-concurrent-tasks"> Spawning Concurrent Tasks</a>
</div>
<div class="nav-entry">
<a class="nav-entry-link" href="concurrency.html#channels"> Channels</a>
</div>
<div class="nav-entry">
<a class="nav-entry-link" href="concurrency.html#shared-objects"> Shared Objects</a>
</div>
</div>
</div>
<div class="nav-group">
<div class="nav-entry is-group-header">
<a class="nav-entry-link" href="json.html">JSON</a>
</div>
<div class="nav-group-body">
<div class="nav-entry">
<a class="nav-entry-link" href="json.html#decoding-json"> Decoding JSON</a>
</div>
<div class="nav-entry">
<a class="nav-entry-link" href="json.html#encoding-json"> Encoding JSON</a>
</div>
</div>
</div>
<div class="nav-group">
<div class="nav-entry is-group-header">
<a class="nav-entry-link" href="testing.html">Testing</a>
</div>
<div class="nav-group-body">
<div class="nav-entry">
<a class="nav-entry-link" href="testing.html#asserts"> Asserts</a>
</div>
<div class="nav-entry">
<a class="nav-entry-link" href="testing.html#asserts-with-an-extra-message"> Asserts with an extra message</a>
</div>
<div class="nav-entry">
<a class="nav-entry-link" href="testing.html#asserts-that-do-not-abort-your-program"> Asserts that do not abort your program</a>
</div>
<div class="nav-entry">
<a class="nav-entry-link" href="testing.html#test-files"> Test files</a>
</div>
<div class="nav-entry">
<a class="nav-entry-link" href="testing.html#running-tests"> Running tests</a>
</div>
</div>
</div>
<div class="nav-group">
<div class="nav-entry is-group-header">
<a class="nav-entry-link" href="memory-management.html">Memory management</a>
</div>
<div class="nav-group-body">
<div class="nav-entry">
<a class="nav-entry-link" href="memory-management.html#control"> Control</a>
</div>
<div class="nav-entry">
<a class="nav-entry-link" href="memory-management.html#stack-and-heap"> Stack and Heap</a>
</div>
</div>
</div>
<div class="nav-group">
<div class="nav-entry is-group-header">
<a class="nav-entry-link" href="orm.html">ORM</a>
</div>
<div class="nav-group-body">
</div>
</div>
<div class="nav-group">
<div class="nav-entry is-group-header">
<a class="nav-entry-link" href="writing-documentation.html">Writing Documentation</a>
</div>
<div class="nav-group-body">
<div class="nav-entry">
<a class="nav-entry-link" href="writing-documentation.html#newlines-in-documentation-comments"> Newlines in Documentation Comments</a>
</div>
</div>
</div>
<div class="nav-group">
<div class="nav-entry is-group-header">
<a class="nav-entry-link" href="tools.html">Tools</a>
</div>
<div class="nav-group-body">
<div class="nav-entry">
<a class="nav-entry-link" href="tools.html#v-fmt"> v fmt</a>
</div>
<div class="nav-entry">
<a class="nav-entry-link" href="tools.html#v-shader"> v shader</a>
</div>
<div class="nav-entry">
<a class="nav-entry-link" href="tools.html#profiling"> Profiling</a>
</div>
</div>
</div>
<div class="nav-group">
<div class="nav-entry is-group-header">
<a class="nav-entry-link" href="package-management.html">Package management</a>
</div>
<div class="nav-group-body">
<div class="nav-entry">
<a class="nav-entry-link" href="package-management.html#package-commands"> Package commands</a>
</div>
<div class="nav-entry">
<a class="nav-entry-link" href="package-management.html#publish-package"> Publish package</a>
</div>
</div>
</div>
<div class="nav-group">
<div class="nav-entry is-group-header">
<a class="nav-entry-link" href="attributes.html">Attributes</a>
</div>
<div class="nav-group-body">
</div>
</div>
<div class="nav-group">
<div class="nav-entry is-group-header">
<a class="nav-entry-link" href="conditional-compilation.html">Conditional compilation</a>
</div>
<div class="nav-group-body">
<div class="nav-entry">
<a class="nav-entry-link" href="conditional-compilation.html#compile-time-pseudo-variables"> Compile time pseudo variables</a>
</div>
<div class="nav-entry">
<a class="nav-entry-link" href="conditional-compilation.html#compile-time-reflection"> Compile time reflection</a>
</div>
<div class="nav-entry">
<a class="nav-entry-link" href="conditional-compilation.html#compile-time-code"> Compile time code</a>
</div>
<div class="nav-entry">
<a class="nav-entry-link" href="conditional-compilation.html#compile-time-types"> Compile time types</a>
</div>
<div class="nav-entry">
<a class="nav-entry-link" href="conditional-compilation.html#environment-specific-files"> Environment specific files</a>
</div>
</div>
</div>
<div class="nav-group">
<div class="nav-entry is-group-header">
<a class="nav-entry-link" href="debugger.html">Debugger</a>
</div>
<div class="nav-group-body">
</div>
</div>
<div class="nav-group">
<div class="nav-entry is-group-header">
<a class="nav-entry-link" href="call-stack.html">Call stack</a>
</div>
<div class="nav-group-body">
</div>
</div>
<div class="nav-group">
<div class="nav-entry is-group-header">
<a class="nav-entry-link" href="trace.html">Trace</a>
</div>
<div class="nav-group-body">
</div>
</div>
<div class="nav-group">
<div class="nav-entry is-group-header">
<a class="nav-entry-link" href="memory-unsafe-code.html">Memory-unsafe code</a>
</div>
<div class="nav-group-body">
</div>
</div>
<div class="nav-group">
<div class="nav-entry is-group-header">
<a class="nav-entry-link" href="structs-with-reference-fields.html">Structs with reference fields</a>
</div>
<div class="nav-group-body">
</div>
</div>
<div class="nav-group">
<div class="nav-entry is-group-header">
<a class="nav-entry-link" href="sizeof-and-__offsetof.html">sizeof and __offsetof</a>
</div>
<div class="nav-group-body">
</div>
</div>
<div class="nav-group">
<div class="nav-entry is-group-header">
<a class="nav-entry-link" href="limited-operator-overloading.html">Limited operator overloading</a>
</div>
<div class="nav-group-body">
<div class="nav-entry">
<a class="nav-entry-link" href="limited-operator-overloading.html#implicitly-generated-overloads"> Implicitly generated overloads</a>
</div>
<div class="nav-entry">
<a class="nav-entry-link" href="limited-operator-overloading.html#restriction"> Restriction</a>
</div>
</div>
</div>
<div class="nav-group">
<div class="nav-entry is-group-header">
<a class="nav-entry-link" href="performance-tuning.html">Performance tuning</a>
</div>
<div class="nav-group-body">
<div class="nav-entry">
<a class="nav-entry-link" href="performance-tuning.html#tuning-operations-details"> Tuning operations details</a>
</div>
</div>
</div>
<div class="nav-group">
<div class="nav-entry is-group-header">
<a class="nav-entry-link" href="atomics.html">Atomics</a>
</div>
<div class="nav-group-body">
</div>
</div>
<div class="nav-group">
<div class="nav-entry is-group-header">
<a class="nav-entry-link" href="global-variables.html">Global Variables</a>
</div>
<div class="nav-group-body">
</div>
</div>
<div class="nav-group">
<div class="nav-entry is-group-header">
<a class="nav-entry-link" href="static-variables.html">Static Variables</a>
</div>
<div class="nav-group-body">
</div>
</div>
<div class="nav-group">
<div class="nav-entry is-group-header">
<a class="nav-entry-link" href="cross-compilation.html">Cross compilation</a>
</div>
<div class="nav-group-body">
</div>
</div>
<div class="nav-group">
<div class="nav-entry is-group-header">
<a class="nav-entry-link" href="debugging.html">Debugging</a>
</div>
<div class="nav-group-body">
<div class="nav-entry">
<a class="nav-entry-link" href="debugging.html#c-backend-binaries-(default)"> C Backend binaries (Default)</a>
</div>
<div class="nav-entry">
<a class="nav-entry-link" href="debugging.html#native-backend-binaries"> Native Backend binaries</a>
</div>
<div class="nav-entry">
<a class="nav-entry-link" href="debugging.html#javascript-backend"> Javascript Backend</a>
</div>
</div>
</div>
<div class="nav-group">
<div class="nav-entry is-group-header">
<a class="nav-entry-link" href="v-and-c.html">V and C</a>
</div>
<div class="nav-group-body">
<div class="nav-entry">
<a class="nav-entry-link" href="v-and-c.html#calling-c-from-v"> Calling C from V</a>
</div>
<div class="nav-entry">
<a class="nav-entry-link" href="v-and-c.html#calling-v-from-c"> Calling V from C</a>
</div>
<div class="nav-entry">
<a class="nav-entry-link" href="v-and-c.html#passing-c-compilation-flags"> Passing C compilation flags</a>
</div>
<div class="nav-entry">
<a class="nav-entry-link" href="v-and-c.html#pkgconfig"> pkgconfig</a>
</div>
<div class="nav-entry">
<a class="nav-entry-link" href="v-and-c.html#including-c-code"> Including C code</a>
</div>
<div class="nav-entry">
<a class="nav-entry-link" href="v-and-c.html#c-types"> C types</a>
</div>
<div class="nav-entry">
<a class="nav-entry-link" href="v-and-c.html#c-declarations"> C Declarations</a>
</div>
<div class="nav-entry">
<a class="nav-entry-link" href="v-and-c.html#export-to-shared-library"> Export to shared library</a>
</div>
<div class="nav-entry">
<a class="nav-entry-link" href="v-and-c.html#translating-c-to-v"> Translating C to V</a>
</div>
<div class="nav-entry">
<a class="nav-entry-link" href="v-and-c.html#working-around-c-issues"> Working around C issues</a>
</div>
</div>
</div>
<div class="nav-group">
<div class="nav-entry is-group-header">
<a class="nav-entry-link" href="other-v-features.html">Other V Features</a>
</div>
<div class="nav-group-body">
<div class="nav-entry">
<a class="nav-entry-link" href="other-v-features.html#inline-assembly"> Inline assembly</a>
</div>
<div class="nav-entry">
<a class="nav-entry-link" href="other-v-features.html#hot-code-reloading"> Hot code reloading</a>
</div>
<div class="nav-entry">
<a class="nav-entry-link" href="other-v-features.html#cross-platform-shell-scripts-in-v"> Cross-platform shell scripts in V</a>
</div>
<div class="nav-entry">
<a class="nav-entry-link" href="other-v-features.html#vsh-scripts-with-no-extension"> Vsh scripts with no extension</a>
</div>
</div>
</div>
<div class="nav-group">
<div class="nav-entry is-group-header">
<a class="nav-entry-link" href="appendix-i-keywords.html">Appendix I: Keywords</a>
</div>
<div class="nav-group-body">
</div>
</div>
<div class="nav-group">
<div class="nav-entry is-group-header">
<a class="nav-entry-link" href="appendix-ii-operators.html">Appendix II: Operators</a>
</div>
<div class="nav-group-body">
</div>
</div>
<div class="nav-group">
<div class="nav-entry is-group-header">
<a class="nav-entry-link" href="other-online-resources.html">Other online resources</a>
</div>
<div class="nav-group-body">
<div class="nav-entry">
<a class="nav-entry-link" href="other-online-resources.html#v-contributing-guide"> V contributing guide</a>
</div>
<div class="nav-entry">
<a class="nav-entry-link" href="other-online-resources.html#v-language-documentation"> V language documentation</a>
</div>
<div class="nav-entry">
<a class="nav-entry-link" href="other-online-resources.html#v-standard-module-documentation"> V standard module documentation</a>
</div>
<div class="nav-entry">
<a class="nav-entry-link" href="other-online-resources.html#v-online-playground"> V online playground</a>
</div>
<div class="nav-entry">
<a class="nav-entry-link" href="other-online-resources.html#awesome-v"> Awesome V</a>
</div>
<div class="nav-entry">
<a class="nav-entry-link" href="other-online-resources.html#the-v-language-discord"> The V language Discord</a>
</div>
</div>
</div>
</div>
</nav>
</aside>
<article>
<div class="container">
<div class="content">
<div class="content-container">
<main class="v-doc">
<h1 class="main">Type Declarations</h1>
<h2 id="type-aliases">Type aliases <a href="type-declarations.html#type-aliases" class="header-anchor" aria-hidden="true">#</a></h2>
<p>To define a new type <code>NewType</code> as an alias for <code>ExistingType</code>,
do <code>type NewType = ExistingType</code>.<br/>
This is a special case of a <a href="type-declarations.html#sum-types">sum type</a> declaration.</p>
<h2 id="enums">Enums <a href="type-declarations.html#enums" class="header-anchor" aria-hidden="true">#</a></h2>
<div class="language-v">enum Color as u8 {
red
green
blue
}
mut color := Color.red
// V knows that `color` is a `Color`. No need to use `color = Color.green` here.
color = .green
println(color) // "green"
match color {
.red { println('the color was red') }
.green { println('the color was green') }
.blue { println('the color was blue') }
}
</div>
<p>The enum type can be any integer type, but can be omitted, if it is <code>int</code>: <code>enum Color {</code>.</p>
<p>Enum match must be exhaustive or have an <code>else</code> branch.
This ensures that if a new enum field is added, it's handled everywhere in the code.</p>
<p>Enum fields can re-use reserved keywords:</p>
<div class="language-v">enum Color {
none
red
green
blue
}
color := Color.none
println(color)
</div>
<p>Integers may be assigned to enum fields.</p>
<div class="language-v">enum Grocery {
apple
orange = 5
pear
}
g1 := int(Grocery.apple)
g2 := int(Grocery.orange)
g3 := int(Grocery.pear)
println('Grocery IDs: ${g1}, ${g2}, ${g3}')
</div>
<p>Output: <code>Grocery IDs: 0, 5, 6</code>.</p>
<p>Operations are not allowed on enum variables; they must be explicitly cast to <code>int</code>.</p>
<p>Enums can have methods, just like structs.</p>
<div class="language-v">enum Cycle {
one
two
three
}
fn (c Cycle) next() Cycle {
match c {
.one {
return .two
}
.two {
return .three
}
.three {
return .one
}
}
}
mut c := Cycle.one
for _ in 0 .. 10 {
println(c)
c = c.next()
}
</div>
<p>Output:</p>
<pre><code>one
two
three
one
two
three
one
two
three
one
</code></pre>
<p>Enums can be created from string or integer value and converted into string</p>
<div class="language-v">enum Cycle {
one
two = 2
three
}
// Create enum from value
println(Cycle.from(10) or { Cycle.three })
println(Cycle.from('two')!)
// Convert an enum value to a string
println(Cycle.one.str())
</div>
<p>Output:</p>
<pre><code>three
two
one
</code></pre>
<h2 id="function-types">Function Types <a href="type-declarations.html#function-types" class="header-anchor" aria-hidden="true">#</a></h2>
<p>You can use type aliases for naming specific function signatures - for
example:</p>
<div class="language-v">type Filter = fn (string) string
</div>
<p>This works like any other type - for example, a function can accept an
argument of a function type:</p>
<div class="language-v">type Filter = fn (string) string
fn filter(s string, f Filter) string {
return f(s)
}
</div>
<p>V has duck-typing, so functions don't need to declare compatibility with
a function type - they just have to be compatible:</p>
<div class="language-v">fn uppercase(s string) string {
return s.to_upper()
}
// now `uppercase` can be used everywhere where Filter is expected
</div>
<p>Compatible functions can also be explicitly cast to a function type:</p>
<div class="language-v">my_filter := Filter(uppercase)
</div>
<p>The cast here is purely informational - again, duck-typing means that the
resulting type is the same without an explicit cast:</p>
<div class="language-v">my_filter := uppercase
</div>
<p>You can pass the assigned function as an argument:</p>
<div class="language-v">println(filter('Hello world', my_filter)) // prints `HELLO WORLD`
</div>
<p>And you could of course have passed it directly as well, without using a
local variable:</p>
<div class="language-v">println(filter('Hello world', uppercase))
</div>
<p>And this works with anonymous functions as well:</p>
<div class="language-v">println(filter('Hello world', fn (s string) string {
return s.to_upper()
}))
</div>
<p>You can see the complete
<a href="https://github.com/vlang/v/tree/master/examples/function_types.v">example here</a>.</p>
<h2 id="interfaces">Interfaces <a href="type-declarations.html#interfaces" class="header-anchor" aria-hidden="true">#</a></h2>
<div class="language-v">// interface-example.1
struct Dog {
breed string
}
fn (d Dog) speak() string {
return 'woof'
}
struct Cat {
breed string
}
fn (c Cat) speak() string {
return 'meow'
}
// unlike Go, but like TypeScript, V's interfaces can define both fields and methods.
interface Speaker {
breed string
speak() string
}