You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/memory-model.md
+5-5Lines changed: 5 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -35,7 +35,7 @@ r[memory.byte.uninit]
35
35
r[memory.encoding]
36
36
37
37
r[memory.encoding.intro]
38
-
Each type in Rust has 0 or more values, which can have operations performed on them. Values are represented in memory by encoding them
38
+
Each type in Rust has 0 or more values, which can have operations performed on them. Values are represented in memory by encoding them
39
39
40
40
> [!NOTE]
41
41
> `0u8`, `1337i16`, and `Foo{bar: "baz"}` are all values
@@ -44,7 +44,7 @@ r[memory.encoding.op]
44
44
Each type defines a pair of properties which, together, define the representation of values of the type. The *encode* operation takes a value of the type and converts it into a sequence of bytes equal in length to the size of the type, and the *decode* operation takes such a sequence of bytes and optionally converts it into a value. Encoding occurs when a value is written to memory, and decoding occurs when a value is read from memory.
45
45
46
46
> [!NOTE]
47
-
> Only certain byte sequences may decode into a value of a given type. For example, a byte sequence consisting of all zeroes does not decode to a value of a reference type.
47
+
> Only certain byte sequences may decode into a value of a given type. For example, a byte sequence consisting of all zeroes does not decode to a value of a reference type.
48
48
49
49
r[memory.encoding.representation]
50
50
A sequence of bytes is said to represent a value of a type, if the decode operation for that type produces that value from that sequence of bytes. The representation of a type is the partial relation between byte sequences and values those sequences represent.
@@ -56,11 +56,11 @@ r[memory.encoding.symmetric]
56
56
The result of encoding a given value of a type is a sequence of bytes that represents that value.
57
57
58
58
> [!NOTE]
59
-
> This means that a value can be copied into memory and copied out and the result is the same value.
59
+
> This means that a value can be copied into memory and copied out and the result is the same value.
60
60
> The reverse is not necessarily true, a sequence of bytes read as a value then written to another location (called a typed copy) will not necessarily yield the same sequence of bytes. For example, a typed copy of a struct type will leave the padding bytes of that struct uninitialized.
61
61
62
62
r[memory.encoding.decode]
63
-
If a value of type `T` is decoded from a sequence of bytes that does not represent any value, the behavior is undefined.
63
+
If a value of type `T` is decoded from a sequence of bytes that does not represent any value, the behavior is undefined.
64
64
65
65
> [!NOTE]
66
-
> For example, it is undefined behavior to read a `0x02` byte as `bool`.
66
+
> For example, it is undefined behavior to read a `0x02` byte as `bool`.
0 commit comments