@@ -2478,13 +2478,16 @@ type `float` may not be equal to the largest *supported* floating-point type.
2478
2478
2479
2479
### Textual types
2480
2480
2481
- The types ` char ` and ` ~ str` hold textual data.
2481
+ The types ` char ` and ` str ` hold textual data.
2482
2482
2483
2483
A value of type ` char ` is a Unicode character, represented as a 32-bit
2484
2484
unsigned word holding a UCS-4 codepoint.
2485
2485
2486
- A value of type ` ~ str` is a Unicode string, represented as a vector of 8-bit
2486
+ A value of type ` str ` is a Unicode string, represented as a vector of 8-bit
2487
2487
unsigned bytes holding a sequence of UTF-8 codepoints.
2488
+ Since ` str ` is of indefinite size, it is not a _ first class_ type,
2489
+ but can only be instantiated through a pointer type,
2490
+ such as ` &str ` , ` @str ` or ` ~str ` .
2488
2491
2489
2492
2490
2493
### Tuple types
@@ -2505,45 +2508,35 @@ order specified by the tuple type.
2505
2508
An example of a tuple type and its use:
2506
2509
2507
2510
~~~~
2508
- type pair = (int,~ str);
2509
- let p: pair = (10,~ "hello");
2511
+ type Pair = (int,& str);
2512
+ let p: Pair = (10,"hello");
2510
2513
let (a, b) = p;
2511
- assert b != ~ "world";
2514
+ assert b != "world";
2512
2515
~~~~
2513
2516
2514
2517
2515
2518
### Vector types
2516
2519
2517
- The vector type-constructor represents a homogeneous array of values of a
2518
- given type. A vector has a fixed size. The kind of a vector type depends on
2519
- the kind of its member type, as with other simple structural types.
2520
+ The vector type-constructor represents a homogeneous array of values of a given type.
2521
+ A vector has a fixed size.
2522
+ A vector type can be accompanied by _ definite_ size, written with a trailing asterisk and integer literal, such as ` [int * 10] ` .
2523
+ Such a definite-sized vector can be treated as a first class type since its size is known statically.
2524
+ A vector without such a size is said to be of _ indefinite_ size,
2525
+ and is therefore not a _ first class_ type,
2526
+ can only be instantiated through a pointer type,
2527
+ such as ` &[T] ` , ` @[T] ` or ` ~[T] ` .
2528
+ The kind of a vector type depends on the kind of its member type, as with other simple structural types.
2520
2529
2521
2530
An example of a vector type and its use:
2522
2531
2523
2532
~~~~
2524
- let v: ~ [int] = ~ [7, 5, 3];
2533
+ let v: & [int] = [7, 5, 3];
2525
2534
let i: int = v[2];
2526
2535
assert (i == 3);
2527
2536
~~~~
2528
2537
2529
- Vectors always * allocate* a storage region sufficient to store the first power
2530
- of two worth of elements greater than or equal to the size of the vector. This
2531
- behaviour supports idiomatic in-place "growth" of a mutable slot holding a
2532
- vector:
2533
-
2534
-
2535
- ~~~~
2536
- let mut v: ~[int] = ~[1, 2, 3];
2537
- v += ~[4, 5, 6];
2538
- ~~~~
2539
-
2540
- Normal vector concatenation causes the allocation of a fresh vector to hold
2541
- the result; in this case, however, the slot holding the vector recycles the
2542
- underlying storage in-place (since the reference-count of the underlying
2543
- storage is equal to 1).
2544
-
2545
- All accessible elements of a vector are always initialized, and access to a
2546
- vector is always bounds-checked.
2538
+ All accessible elements of a vector are always initialized, and access to a vector is always bounds-checked.
2539
+ In the case of a definite-
2547
2540
2548
2541
2549
2542
### Structure types
0 commit comments