description = "Aquesta publicació mostra alguns exemples de format en Markdown, incloent-hi una taula, blocs de codi i etiquetes, citacions, taules i notes a peu de pàgina."
[taxonomies]
@ -59,6 +59,42 @@ fn main() {
}
```
### Amb numeració de línies
```rust,linenos
use std::collections::HashMap;
#[derive(Debug)]
struct TwinPeaksCharacter {
name: String,
coffee_rating: f32,
pie_preference: String,
}
fn main() {
let mut black_lodge = HashMap::new();
black_lodge.insert("agent", TwinPeaksCharacter {
name: String::from("Dale Cooper"),
coffee_rating: 9999.99,
pie_preference: String::from("Damn Fine Cherry"),
});
black_lodge.insert("giant", TwinPeaksCharacter {
name: String::from("The Fireman"),
coffee_rating: 42.424242,
pie_preference: String::from("Garmonbozia"),
});
// Calculate total appreciation of damn fine coffee
let total_coffee: f32 = black_lodge.values()
.map(|character| character.coffee_rating)
.sum();
println!("☕ Total coffee appreciation: {:.2} cups", total_coffee);
}
```
## Etiquetes de codi
A Rust, declares una variable mutable amb `let mut x = 5;`, mentre que a Python, simplement fas `x = 5`. De manera similar, per imprimir un valor a Rust, utilitzaries `println!("Valor: {}", x);`, però a Python, és tan senzill com `print(f"Valor: {x}")`.
description = "Esta publicación muestra algunos ejemplos de formato Markdown, incluyendo una tabla, bloques de código y etiquetas, citas, tablas y notas al pie de página."
[taxonomies]
@ -59,6 +59,42 @@ fn main() {
}
```
### Con números de línea
```rust,linenos
use std::collections::HashMap;
#[derive(Debug)]
struct TwinPeaksCharacter {
name: String,
coffee_rating: f32,
pie_preference: String,
}
fn main() {
let mut black_lodge = HashMap::new();
black_lodge.insert("agent", TwinPeaksCharacter {
name: String::from("Dale Cooper"),
coffee_rating: 9999.99,
pie_preference: String::from("Damn Fine Cherry"),
});
black_lodge.insert("giant", TwinPeaksCharacter {
name: String::from("The Fireman"),
coffee_rating: 42.424242,
pie_preference: String::from("Garmonbozia"),
});
// Calculate total appreciation of damn fine coffee
let total_coffee: f32 = black_lodge.values()
.map(|character| character.coffee_rating)
.sum();
println!("☕ Total coffee appreciation: {:.2} cups", total_coffee);
}
```
## Etiquetas de código
En Rust, declaras una variable mutable con `let mut x = 5;`, mientras que en Python, simplemente usas `x = 5`. De manera similar, para imprimir un valor en Rust, utilizarías `println!("Valor: {}", x);`, pero en Python, es tan sencillo como `print(f"Valor: {x}")`.
description = "This post showcases some examples of Markdown formatting, including a table, code blocks and tags, quotes, tables, and footnotes."
[taxonomies]
@ -59,6 +59,42 @@ fn main() {
}
```
### With line numbers
```rust,linenos
use std::collections::HashMap;
#[derive(Debug)]
struct TwinPeaksCharacter {
name: String,
coffee_rating: f32,
pie_preference: String,
}
fn main() {
let mut black_lodge = HashMap::new();
black_lodge.insert("agent", TwinPeaksCharacter {
name: String::from("Dale Cooper"),
coffee_rating: 9999.99,
pie_preference: String::from("Damn Fine Cherry"),
});
black_lodge.insert("giant", TwinPeaksCharacter {
name: String::from("The Fireman"),
coffee_rating: 42.424242,
pie_preference: String::from("Garmonbozia"),
});
// Calculate total appreciation of damn fine coffee
let total_coffee: f32 = black_lodge.values()
.map(|character| character.coffee_rating)
.sum();
println!("☕ Total coffee appreciation: {:.2} cups", total_coffee);
}
```
## Code tags
In Rust, you declare a mutable variable with `let mut x = 5;`, whereas in Python, you simply use `x = 5`. Similarly, to print a value in Rust, you would use `println!("Value: {}", x);`, but in Python, it's as straightforward as `print(f"Value: {x}")`.