2
2
3
3
### Terminology
4
4
5
- Reference types are types of the form ` &T ` , ` &mut T ` or ` &dyn T ` .
5
+ Reference types are types of the form ` &T ` , ` &mut T ` .
6
6
7
7
Raw pointer types are types of the form ` *const T ` or ` *mut T ` .
8
- We write ` *T ` when the mutability attribute is unimportant.
9
8
10
9
### Representation
11
10
12
11
The alignment of ` &T ` , ` &mut T ` , ` *const T ` and ` *mut T ` are the same,
13
12
and are at least the word size.
14
13
15
- * If ` T ` is a trait, then the alignment of ` &dyn T ` is the word size.
16
14
* If ` T ` is a sized type then the alignment of ` &T ` is the word size.
15
+ * The alignment of ` &dyn Trait ` is the word size.
17
16
* The alignment of ` &[T] ` is the word size.
18
17
* The alignment of ` &str ` is the word size.
19
18
* Alignment in other cases may be more than the word size (e.g., for other dynamically sized types).
20
19
21
20
The sizes of ` &T ` , ` &mut T ` , ` *const T ` and ` *mut T ` are the same,
22
21
and are at least one word.
23
22
24
- * If ` T ` is a trait, then the size of ` &dyn T ` is two words.
25
23
* If ` T ` is a sized type then the size of ` &T ` is one word.
24
+ * The size of ` &dyn Trait ` is two words.
26
25
* The size of ` &[T] ` is two words.
27
26
* The size of ` &str ` is two words.
28
27
* Size in other cases may be more than one word (e.g., for other dynamically sized types).
29
28
30
29
### Notes
31
30
32
- The layouts of ` &T ` , ` &mut T ` and ` *T ` are the same.
31
+ The layouts of ` &T ` , ` &mut T ` , ` *const T ` and ` *mut T ` are the same.
33
32
34
33
If ` T ` is sized, references and pointers to ` T ` have a size and alignment of one
35
34
word and have therefore the same layout as C pointers.
@@ -40,23 +39,23 @@ word and have therefore the same layout as C pointers.
40
39
> or, in the case of ` &mut T ` , aliasing.
41
40
42
41
We do not make any guarantees about the layout of
43
- multi-trait objects ` &(dyn T + U ) ` or references to other dynamically sized types,
42
+ multi-trait objects ` &(dyn Tr + Ur ) ` or references to other dynamically sized types,
44
43
other than that they are at least word-aligned, and have size at least one word.
45
44
46
- The layout of ` &dyn T ` when ` T ` is a trait is the same as that of:
47
- ``` rust,ignore
45
+ The layout of ` &dyn Trait ` when ` Trait ` is a trait is the same as that of:
46
+ ``` rust
48
47
#[repr(C )]
49
48
struct DynObject {
50
- data: *u8,
51
- vtable: *u8,
49
+ data : * const u8 ,
50
+ vtable : * const u8 ,
52
51
}
53
52
```
54
53
55
54
The layout of ` &[T] ` is the same as that of:
56
- ``` rust,ignore
55
+ ``` rust
57
56
#[repr(C )]
58
57
struct Slice <T > {
59
- ptr: *T,
58
+ ptr : * const T ,
60
59
len : usize ,
61
60
}
62
61
```
0 commit comments