Skip to content

Commit 2d1a694

Browse files
authored
Merge pull request mouredev#3160 from gabrielmoris/gabrielmoris/rust
#00 - rust
2 parents f833596 + c7f040c commit 2d1a694

File tree

1 file changed

+68
-0
lines changed
  • Roadmap/00 - SINTAXIS, VARIABLES, TIPOS DE DATOS Y HOLA MUNDO/rust

1 file changed

+68
-0
lines changed
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/// https://www.rust-lang.org/
2+
3+
/*
4+
This is a
5+
multi-line
6+
block comment
7+
*/
8+
9+
fn main() {
10+
// Constant Variables
11+
let _string = "Hello";
12+
let _string2 = "Rust";
13+
// Mutables
14+
let mut _y = 10;
15+
_y = 20;
16+
17+
// Strings
18+
let _str: &str = " This is a string";
19+
20+
// Integers
21+
let _int: i32 = 42;
22+
23+
// Floating points
24+
let _fl1: f64 = 3.1416;
25+
26+
//Booleans
27+
let _bool: bool = false;
28+
29+
// Characters
30+
let _char: char = '😂';
31+
32+
// tuples
33+
let _tup: (i32, f64, bool) = (2, 1.5, false);
34+
35+
// Arrays
36+
let _arr: [i32; 4] = [1, 5, 7, 9];
37+
38+
// Objects: 1. define structure and create the instance.
39+
struct Person {
40+
_name: String,
41+
_age: u32,
42+
}
43+
44+
let _person: Person = Person {
45+
_name: String::from("Alice"),
46+
_age: 30,
47+
};
48+
49+
// Classes: 1. Define structure, add constructor and methods
50+
impl Person {
51+
// Constructor function
52+
fn _new(_name: &str, _age: u32) -> Person {
53+
Person {
54+
_name: String::from(_name),
55+
_age,
56+
}
57+
}
58+
59+
// Method to greet the person
60+
fn _greet(&self) {
61+
println!("Hello, my name is {} and I'm {} years old.", self._name, self._age);
62+
}
63+
}
64+
65+
let _person = Person::_new("Gabrielmoris", 34);
66+
67+
println!("{_string}, {_string2}");
68+
}

0 commit comments

Comments
 (0)