389
389
` [mut T] ` Mutable vector with unknown size
390
390
------------------------- -----------------------------------------------
391
391
392
+ In function types, the return type is specified with an arrow, as in
393
+ the type ` fn() -> bool ` or the function declaration `fn foo() -> bool
394
+ { }`. For functions that do not return a meaningful value, you can
395
+ optionally write ` -> () ` , but usually the return annotation is simply
396
+ left off, as in ` fn main() { ... } ` .
397
+
392
398
Types can be given names with ` type ` declarations:
393
399
394
400
~~~~
@@ -402,28 +408,6 @@ error. Read about [single-variant enums](#single_variant_enum)
402
408
further on if you need to create a type name that's not just a
403
409
synonym.
404
410
405
- ## Using types
406
-
407
- The ` -> bool ` in the ` is_four ` example is the way a function's return
408
- type is written. For functions that do not return a meaningful value,
409
- you can optionally say ` -> () ` , but usually the return annotation is simply
410
- left off, as in the ` fn main() { ... } ` examples we've seen earlier.
411
-
412
- Every argument to a function must have its type declared (for example,
413
- ` x: int ` ). Inside the function, type inference will be able to
414
- automatically deduce the type of most locals (generic functions, which
415
- we'll come back to later, will occasionally need additional
416
- annotation). Locals can be written either with or without a type
417
- annotation:
418
-
419
- ~~~~
420
- // The type of this vector will be inferred based on its use.
421
- let x = [];
422
- # vec::map(x, fn&(_y: &int) -> int { *_y });
423
- // Explicitly say this is a vector of zero integers.
424
- let y: [int * 0] = [];
425
- ~~~~
426
-
427
411
## Numeric literals
428
412
429
413
Integers can be written in decimal (` 144 ` ), hexadecimal (` 0x90 ` ), and
0 commit comments