Skip to content

Commit f1b594e

Browse files
authored
fixup up rust init
1 parent a888410 commit f1b594e

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

_languages/rust-struct-initializer-mistake.md

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ fn main() {
103103
}
104104
```
105105

106-
##### How to Distinguish between a variable assigment and a named parameter use inside a function invocation?
106+
#### How to Distinguish between a variable assigment and a named parameter use inside a function invocation?
107107

108108
Example:
109109

@@ -117,11 +117,11 @@ Two points have to be considered here:
117117
- Frequency: Are variable assignments within function calls or function calls with named parameters projected to be used more often?
118118
- Intuitivity: How can the syntax be distributed to those two use-cases such that the configuration makes sense from a user point-of-view?
119119
2. Reducing the harm from mix-ups:
120-
- Can code that looks correct behave unexpectedly
120+
- Can code that looks correct be interpreted unexpectedly? I. e.
121121

122122
In general, there are multiple options:
123123

124-
###### Try to use the same syntax for both variable assigments and named parameters
124+
##### Try to use the same syntax for both variable assigments and named parameters
125125

126126
This means that named parameters simply act like another scope in which identifiers are looked up.
127127

@@ -134,7 +134,7 @@ The danger with this approach is that changing the name of a named parameter can
134134

135135
It also means that variables with the same name as a parameter name cannot be assigned within a function call.
136136

137-
###### Let variable assignments use the "good" syntax and give named parameters some workaround syntax
137+
##### Let variable assignments use the "good" syntax and give named parameters some workaround syntax
138138

139139
In this example, the orkaround syntax for named parameters is a `.` prefixed to the parameter name.
140140

@@ -148,8 +148,7 @@ In this example, the orkaround syntax for named parameters is a `.` prefixed to
148148
someFunction(.a = 23)
149149

150150

151-
152-
###### Let named parameters use the "good" syntax and give variable assignments some workaround syntax
151+
##### Let named parameters use the "good" syntax and give variable assignments some workaround syntax
153152

154153
Inside a functions argument list, the first level of `=` use is always a named parameter and never a
155154
variable assignment, even if some variable `a` would be in scope.[^2]

0 commit comments

Comments
 (0)