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: docs/bindings.md
+37Lines changed: 37 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -42,3 +42,40 @@ This should be used sparingly, since it can come with either a performance hit,
42
42
:::tip
43
43
The compiler will automatically inline `let` bindings if they are only referenced a single time.
44
44
:::
45
+
46
+
## Destructuring
47
+
48
+
You can destructure values (including `let` bindings and function parameters) into multiple bindings at once.
49
+
50
+
For example, if you have a pair, you can destructure the first and rest values into separate bindings:
51
+
52
+
```rue
53
+
let (first, rest) = (100, 200);
54
+
```
55
+
56
+
This also works for lists (as long as the values are known to not be nil):
57
+
58
+
```rue
59
+
let [a, b, c] = [100, 200, 300];
60
+
```
61
+
62
+
If you have a struct, you can destructure the fields:
63
+
64
+
```rue
65
+
struct Point {
66
+
x: Int,
67
+
y: Int,
68
+
}
69
+
70
+
let { x, y } = Point { x: 100, y: 200 };
71
+
```
72
+
73
+
These destructuring patterns can be combined arbitrarily:
74
+
75
+
```rue
76
+
let ([a, b, c], { x, y }) = ([100, 200, 300], Point { x: 400, y: 500 });
77
+
```
78
+
79
+
:::note
80
+
When you destructure a value, it's first assigned to a temporary binding, and then that binding is referenced by each of the bindings in the destructuring pattern. Thus, if you're destructuring a non-inline variable, it's best to mark the destructured bindings as `inline` to reduce the size of the compiled program.
Copy file name to clipboardExpand all lines: docs/type-system/atoms.md
+13-8Lines changed: 13 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -11,14 +11,15 @@ There are multiple types of atoms:
11
11
1.**Atom** - has no semantic meaning
12
12
2.**Bytes** - explicitly treated as bytes
13
13
3.**Bytes32** - a `Bytes` value with a length of 32
14
-
4.**PublicKey** - a [BLS12-381](https://en.wikipedia.org/wiki/BLS_digital_signature) public key with a length of 48 bytes
15
-
5.**Signature** - a [BLS12-381](https://en.wikipedia.org/wiki/BLS_digital_signature) signature with a length of 96 bytes
16
-
6.**K1PublicKey** - a secp256k1 public key with a length of 33 bytes
17
-
7.**K1Signature** - a secp256k1 signature with a length of 64 bytes
18
-
8.**R1PublicKey** - a secp256r1 public key with a length of 33 bytes
19
-
9.**R1Signature** - a secp256r1 signature with a length of 64 bytes
20
-
10.**Int** - a signed integer of arbitrary size
21
-
11.**Bool** - either `true` or `false`
14
+
4.**String** - a UTF-8 encoded string
15
+
5.**PublicKey** - a [BLS12-381](https://en.wikipedia.org/wiki/BLS_digital_signature) public key with a length of 48 bytes
16
+
6.**Signature** - a [BLS12-381](https://en.wikipedia.org/wiki/BLS_digital_signature) signature with a length of 96 bytes
17
+
7.**K1PublicKey** - a secp256k1 public key with a length of 33 bytes
18
+
8.**K1Signature** - a secp256k1 signature with a length of 64 bytes
19
+
9.**R1PublicKey** - a secp256r1 public key with a length of 33 bytes
20
+
10.**R1Signature** - a secp256r1 signature with a length of 64 bytes
21
+
11.**Int** - a signed integer of arbitrary size
22
+
12.**Bool** - either `true` or `false`
22
23
23
24
## Atom
24
25
@@ -56,6 +57,10 @@ This will emit code at runtime to check that the value has a length of 32.
56
57
`Bytes32` can only guarantee the length of trusted values. See the [Security](/docs/security.md#untrusted-values) page for more details.
57
58
:::
58
59
60
+
## String
61
+
62
+
The `String` type represents a UTF-8 encoded string. It's functionally equivalent to `Bytes`, but provides a more descriptive name for working with text values, and hints to the compiler that the value is a string rather than a sequence of bytes (which is useful for error messages).
63
+
59
64
## PublicKey
60
65
61
66
The `PublicKey` type represents a [BLS12-381](https://en.wikipedia.org/wiki/BLS_digital_signature) public key (also commonly referred to as a G1 element).
Copy file name to clipboardExpand all lines: docs/type-system/structs.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -77,10 +77,10 @@ While the type can technically be inferred, it's often necessary to explicitly u
77
77
Default values are always inlined exactly as written. If the value is expensive to compute, or would require a lot of bytes to duplicate in the output program, it should be extracted out into a constant:
0 commit comments