migration

This commit is contained in:
gbrochar 2020-12-04 18:26:40 +01:00
parent ceef29137a
commit 8e26ffa184
11 changed files with 115 additions and 0 deletions

1
.gitignore vendored
View File

@ -2,6 +2,7 @@
# Generated by Cargo
# will have compiled files and executables
/target/
target
# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html

10
guessing_game/Cargo.toml Normal file
View File

@ -0,0 +1,10 @@
[package]
name = "guessing_game"
version = "0.1.0"
authors = ["gbrochar <gaetanbrochard@protonmail.com>"]
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
rand = "0.5.5"

32
guessing_game/src/main.rs Normal file
View File

@ -0,0 +1,32 @@
use std::io;
use std::cmp::Ordering;
use rand::Rng;
fn main() {
println!("Guess the number !");
let secret_number = rand::thread_rng().gen_range(1, 101);
loop {
println!("Please input your guess.");
let mut guess = String::new();
io::stdin()
.read_line(&mut guess)
.expect("Failed to read line");
let guess: u32 = match guess.trim().parse() {
Ok(num) => num,
Err(_) => continue,
};
println!("You guessed: {}", guess);
match guess.cmp(&secret_number) {
Ordering::Less => println!("Too small!"),
Ordering::Greater => println!("Too big!"),
Ordering::Equal => {
println!("You win!");
break;
}
}
}
}

9
hello_cargo/Cargo.toml Normal file
View File

@ -0,0 +1,9 @@
[package]
name = "hello_cargo"
version = "0.1.0"
authors = ["gbrochar <gaetanbrochard@protonmail.com>"]
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]

3
hello_cargo/src/main.rs Normal file
View File

@ -0,0 +1,3 @@
fn main() {
println!("Hello, world!");
}

BIN
hello_world/main Executable file

Binary file not shown.

3
hello_world/main.rs Normal file
View File

@ -0,0 +1,3 @@
fn main() {
println!("Hello, world!");
}

9
rectangles/Cargo.toml Normal file
View File

@ -0,0 +1,9 @@
[package]
name = "rectangles"
version = "0.1.0"
authors = ["gbrochar <gaetanbrochard@protonmail.com>"]
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]

29
rectangles/src/main.rs Normal file
View File

@ -0,0 +1,29 @@
#[derive(Debug)]
struct Rectangle {
width: u32,
height: u32,
}
impl Rectangle {
fn area(&self) -> u32 {
self.width * self.height
}
fn add_height(&mut self) {
self.height += 1;
}
}
fn main() {
let mut rect1 = Rectangle {
width: 30,
height: 50,
};
println!(
"The area of the rectangle is {} square pixels.",
rect1.area()
);
rect1.add_height();
println!("{:#?}", rect1);
}

9
strlen/Cargo.toml Normal file
View File

@ -0,0 +1,9 @@
[package]
name = "strlen"
version = "0.1.0"
authors = ["gbrochar <gaetanbrochard@protonmail.com>"]
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]

10
strlen/src/main.rs Normal file
View File

@ -0,0 +1,10 @@
fn main() {
let s1 = String::from("hello");
let len = calculate_length(&s1);
println!("The length of '{}' is {}.", s1, len);
}
fn calculate_length(s: &String) -> usize {
s.len()
}