Skip to content

Commit f29b922

Browse files
committed
fix: exclude no_run Go code blocks from selection for Run button
1 parent fd9ed23 commit f29b922

File tree

4 files changed

+110
-90
lines changed

4 files changed

+110
-90
lines changed

src/es/quick-comparisons/casting.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Tanto Go como Rust tienen casteos explicitos, para transformar en Go un tipo de
44
dato a otro generalmente se ejecuta una función como puede verse en el ejemplo
55
de abajo.
66

7-
```go
7+
```go,no_run
88
var x int = 10
99
var y float64 = float64(x)
1010
var z int32 = int32(x)
@@ -16,7 +16,7 @@ En Rust también esto también requerira un casting explicito, pe´ro en lugar d
1616
usando una función con el nombre del tipo, utilizamos directamente la keyword
1717
`as` como se puede ver en el ejemplo de abajo:
1818

19-
```rust
19+
```rust,no_run
2020
let x: i32 = 10;
2121
let y: f64 = x as f64;
2222
let z: u8 = x as u8;
@@ -25,7 +25,7 @@ let z: u8 = x as u8;
2525
Al igual que en Go, Rust al el operador as trunca o satura en algunos casos
2626
(por ejemplo, de i32 a u8).
2727

28-
```rust
28+
```rust,no_run
2929
let big: u32 = 300;
3030
let small: u8 = big as u8;
3131
```
@@ -45,28 +45,28 @@ función asociada/método gracias a ese trait.
4545

4646
Por lo que podríamos hacer
4747

48-
```rust
48+
```rust,no_run
4949
let s = String::from(42);
5050
```
5151

5252
Pero también tendríamos el método `.into()`:
5353

5454

55-
```rust
55+
```rust,no_run
5656
let s: String = 42.into();
5757
```
5858

5959
También podrían haber alternativas drásticamente diferentes como:
6060

61-
```rust
61+
```rust,no_run
6262
let s = 42.to_string();
6363
```
6464

6565
Sin embargo la forma más segura de hacer una conversión entre tipos es con
6666
`TryFrom`, ya que con este trait podemos validar si hay algún error durante la
6767
conversión:
6868

69-
```rust
69+
```rust,no_run
7070
let n: i32 = 300;
7171
let r: Result<u8, _> = n.try_into();
7272
```
@@ -107,7 +107,7 @@ Rust provee estas funciones que te permiten capturar los posibles errores.
107107
En Go si quisieras hacer lo que hace el `try_from()` o el `try_into()` debes
108108
validarlo a mano como con algo así:
109109

110-
```go
110+
```go,no_run
111111
if x >= 0 && x <= 255 {
112112
var y uint8 = uint8(x)
113113
fmt.Println("Seguro:", y)
@@ -118,7 +118,7 @@ if x >= 0 && x <= 255 {
118118

119119
En Rust si inferimos el error podríamos tener algo como esto:
120120

121-
```rust
121+
```rust,no_run
122122
let n: i32 = 300;
123123
let r = u8::try_from(n);
124124
```

src/es/quick-comparisons/control-flow.md

Lines changed: 92 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ En Go suele representarse el control de flujo de esta forma:
4040
# func main() {
4141
# x := 0
4242
if x > 0 {
43-
fmt.Println("positivo")
43+
fmt.Println("positivo")
4444
} else {
45-
fmt.Println("negativo")
45+
fmt.Println("negativo")
4646
}
4747
# }
4848
```
@@ -60,9 +60,9 @@ En Go suele representarse el control de flujo de esta forma:
6060
# func main() {
6161
# x := 1
6262
if x > 0 {
63-
fmt.Println("positivo")
63+
fmt.Println("positivo")
6464
} else {
65-
fmt.Println("negativo")
65+
fmt.Println("negativo")
6666
}
6767
# }
6868
```
@@ -88,26 +88,26 @@ Rust lo representaría de forma similar:
8888
<td>
8989

9090
```rust
91-
# let x = 0;
92-
#
93-
if x > 0 {
94-
println!("positivo");
95-
} else {
96-
println!("negativo");
97-
}
91+
#let x = 0;
92+
#
93+
if x > 0 {
94+
println!("positivo");
95+
} else {
96+
println!("negativo");
97+
}
9898
```
9999

100100
</td>
101101
<td>
102102

103103
```rust
104-
# let x = 1;
105-
#
106-
if x > 0 {
107-
println!("positivo");
108-
} else {
109-
println!("negativo");
110-
}
104+
# let x = 1;
105+
#
106+
if x > 0 {
107+
println!("positivo");
108+
} else {
109+
println!("negativo");
110+
}
111111
```
112112

113113
</td>
@@ -117,8 +117,10 @@ if x > 0 {
117117

118118
Pero en Rust podemos además asignar el resultado de la expresión a una variable:
119119

120-
```rust,ignore
121-
let mensaje = if x > 0 { "positivo" } else { "negativo" };
120+
```rust
121+
#let x = 0;
122+
let mensaje = if x > 0 { "positivo" } else { "negativo" };
123+
#println!("{mensaje}")
122124
```
123125

124126
### Switch vs Match
@@ -139,24 +141,34 @@ let mensaje = if x > 0 { "positivo" } else { "negativo" };
139141
Ejemplo en Go:
140142

141143
```go
142-
switch day {
143-
case "lunes":
144-
fmt.Println("Inicio de semana")
145-
case "viernes":
146-
fmt.Println("Casi fin")
147-
default:
148-
fmt.Println("Otro día")
149-
}
144+
#package main
145+
#
146+
#import (
147+
# "fmt"
148+
#)
149+
#
150+
#func main() {
151+
# day := "lunes"
152+
switch day {
153+
case "lunes":
154+
fmt.Println("Inicio de semana")
155+
case "viernes":
156+
fmt.Println("Casi fin")
157+
default:
158+
fmt.Println("Otro día")
159+
}
160+
#}
150161
```
151162

152163
En Rust, el equivalente sería:
153164

154-
```rust,ignore
155-
match day {
156-
"lunes" => println!("Inicio de semana"),
157-
"viernes" => println!("Casi fin"),
158-
_ => println!("Otro día"),
159-
}
165+
```rust
166+
# let day = "lunes";
167+
match day {
168+
"lunes" => println!("Inicio de semana"),
169+
"viernes" => println!("Casi fin"),
170+
_ => println!("Otro día"),
171+
}
160172
```
161173

162174
### Bucles
@@ -171,47 +183,55 @@ match day {
171183
En Go podríamos hacer lo siguiente:
172184

173185
```go
174-
for i := 0; i < 5; i++ {
175-
fmt.Println(i)
176-
}
186+
#package main
187+
#
188+
#import (
189+
# "fmt"
190+
#)
191+
#
192+
#func main() {
193+
for i := 0; i < 5; i++ {
194+
fmt.Println(i)
195+
}
196+
#}
177197
```
178198

179199
En Rust de forma similar podríamos conseguir el mismo efecto:
180200

181201
```rust
182-
for i in 0..5 {
183-
println!("{}", i);
184-
}
202+
for i in 0..5 {
203+
println!("{}", i);
204+
}
185205
```
186206

187207
#### Bucle Infinito
188208

189209
En Go un bucle infinito podríamos hacerlo de la siguiente forma:
190210

191-
```go
192-
for {
193-
fmt.Println("infinito")
194-
}
211+
```go,no_run
212+
for {
213+
fmt.Println("infinito")
214+
}
195215
```
196216

197217
Mientras que en Rust usaríamos:
198218

199-
```rust,ignore
200-
loop {
201-
println!("infinito");
202-
}
219+
```rust,no_run
220+
loop {
221+
println!("infinito");
222+
}
203223
```
204224

205225
#### Bucles con While
206226

207227
Go no tiene bucle `while` pero en Rust si tenemos.
208228

209229
```rust
210-
let mut i = 0;
211-
while i < 5 {
212-
println!("{}", i);
213-
i += 1;
214-
}
230+
let mut i = 0;
231+
while i < 5 {
232+
println!("{}", i);
233+
i += 1;
234+
}
215235
```
216236

217237
El bucle `while` puede resultar útil cuando buscamos una condición de corte
@@ -224,16 +244,16 @@ contadores.
224244
Ambos lenguajes los tienen, pero Rust permite `break` con valor en `loop`:
225245

226246
```rust
227-
let mut x = 0;
247+
let mut x = 0;
228248

229-
let resultado = loop {
230-
if x > 10 {
231-
break x * 2; // aquí
232-
}
233-
x += 1;
234-
};
249+
let resultado = loop {
250+
if x > 10 {
251+
break x * 2; // aquí
252+
}
253+
x += 1;
254+
};
235255

236-
println!("{resultado}");
256+
println!("{resultado}");
237257
```
238258

239259
De esta forma se asigna el valor del `break` dentro de `resultado`.
@@ -258,11 +278,11 @@ Eso no existe en Go.
258278
Rust permite patrones destructurantes muy potentes que no existen en Go.
259279

260280
```rust
261-
let punto = (0, 5);
281+
let punto = (0, 5);
262282

263-
if let (0, y) = punto {
264-
println!("Está sobre el eje Y en {y}");
265-
}
283+
if let (0, y) = punto {
284+
println!("Está sobre el eje Y en {y}");
285+
}
266286
```
267287

268288
En este caso si `opcion` es equivalente a la variante `Some`, se extrae el valor
@@ -275,13 +295,13 @@ Con `match` podríamos hacer algo similar, pero en este caso debemos cubrir amba
275295
variantes, el `match` es exhaustivo, sino tenemos en cuenta ambos casos
276296
obtendremos un error en compilación:
277297

278-
```rust
279-
let color = "azul";
298+
```rust,editable
299+
let color = "azul";
280300
281-
match color {
282-
"rojo" => println!("El color es rojo"),
283-
"verde" => println!("El color es verde"),
284-
otro => println!("Otro color, el cual es {otro}"),
285-
}
301+
match color {
302+
"rojo" => println!("El color es rojo"),
303+
"verde" => println!("El color es verde"),
304+
otro => println!("Otro color, el cual es {otro}"),
305+
}
286306
```
287307

0 commit comments

Comments
 (0)