Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Review and add improvements #1

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion section_1/1.5/hello-rust/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
# Generated by Cargo
# will have compiled files and executables
debug/
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
Cargo.lock

# These are backup files generated by rustfmt
**/*.rs.bk

# MSVC Windows builds of rustc generate these, which store debugging information
*.pdb
2 changes: 1 addition & 1 deletion section_1/1.5/hello-rust/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
fn main() {
let text = "Hello, Rust!";
let text = "Hello, Rust!";
println!("{}", text);
}
13 changes: 12 additions & 1 deletion section_2/2.1/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
# Generated by Cargo
# will have compiled files and executables
debug/
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
Cargo.lock

# These are backup files generated by rustfmt
**/*.rs.bk

# MSVC Windows builds of rustc generate these, which store debugging information
*.pdb
4 changes: 2 additions & 2 deletions section_2/2.1/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
fn main() {
let mut x = 5;
let mut x = 5;

x = 4;
x = 4;
}
13 changes: 12 additions & 1 deletion section_2/2.2/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
# Generated by Cargo
# will have compiled files and executables
debug/
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
Cargo.lock

# These are backup files generated by rustfmt
**/*.rs.bk

# MSVC Windows builds of rustc generate these, which store debugging information
*.pdb
3 changes: 3 additions & 0 deletions section_2/2.2/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
mod operators;

fn main() {
let tup: (u8, i8, f32) = (1, -1, 3.5);
println!("{tup:?}");
}
15 changes: 8 additions & 7 deletions section_2/2.2/src/operators.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@


let addition = 2 + 2;
let subtraction = 4 - 3;
let multiplication = 2 * 2;
let division = 4 / 2;
let remainder = 4 % 2;
#[test]
fn test() {
let _addition = 2 + 2;
let _subtraction = 4 - 3;
let _multiplication = 2 * 2;
let _division = 4 / 2;
let _remainder = 4 % 2;
}
13 changes: 12 additions & 1 deletion section_2/2.3/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
# Generated by Cargo
# will have compiled files and executables
debug/
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
Cargo.lock

# These are backup files generated by rustfmt
**/*.rs.bk

# MSVC Windows builds of rustc generate these, which store debugging information
*.pdb
36 changes: 17 additions & 19 deletions section_2/2.3/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,26 +1,24 @@
fn main() {

let name = "Alex";
let name = "Alex";

match name {
"Dave" => println!("Oh hiya Dave!"),
"Sally" => println!("Hi Sally!"),
_ => println!("Wait, I don't know you!")
}
match name {
"Dave" => println!("Oh hiya Dave!"),
"Sally" => println!("Hi Sally!"),
_ => println!("Wait, I don't know you!"),
}

//loop {
// println!("Rust\n");
//}

//loop {
// println!("Rust\n");
//}
//for x in 0..10{
// println!("{}", x);
//}

//for x in 0..10{
// println!("{}", x);
//}
//let mut counter = 1;
//while counter != 10 {
// println!("Counter: {}", counter);

//let mut counter = 1;
//while counter != 10 {
// println!("Counter: {}", counter);

// counter = counter + 1;
//}
// counter = counter + 1;
//}
}
13 changes: 12 additions & 1 deletion section_2/2.4/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
# Generated by Cargo
# will have compiled files and executables
debug/
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
Cargo.lock

# These are backup files generated by rustfmt
**/*.rs.bk

# MSVC Windows builds of rustc generate these, which store debugging information
*.pdb
3 changes: 3 additions & 0 deletions section_2/2.4/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,7 @@ fn main() {
let array = ["This", "is", "an", "array"];

let array_slice = &array[1..4];

println!("{array:?}");
println!("{array_slice:?}");
}
13 changes: 12 additions & 1 deletion section_2/2.5/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
# Generated by Cargo
# will have compiled files and executables
debug/
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
Cargo.lock

# These are backup files generated by rustfmt
**/*.rs.bk

# MSVC Windows builds of rustc generate these, which store debugging information
*.pdb
10 changes: 10 additions & 0 deletions section_2/2.5/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,13 @@ version = "0.1.0"
authors = ["TheAdnan <adnankicin92@gmail.com>"]

[dependencies]

# cargo run --bin main
[[bin]]
name="main"
path="src/main.rs"

# cargo run --bin ownership
[[bin]]
name="ownership"
path="src/ownership.rs"
6 changes: 3 additions & 3 deletions section_2/2.5/src/ownership.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
fn main() {

#[allow(unused_assignments)]
let mut string1: String = String::new();

string1 = "String".to_string();

let string2 = &string;
let string2 = &string1;

println!("{:?}", string);
println!("{:?}", string1);

println!("{:?}", string2);

Expand Down
13 changes: 12 additions & 1 deletion section_3/3.1/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
# Generated by Cargo
# will have compiled files and executables
debug/
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
Cargo.lock

# These are backup files generated by rustfmt
**/*.rs.bk

# MSVC Windows builds of rustc generate these, which store debugging information
*.pdb
5 changes: 3 additions & 2 deletions section_3/3.1/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
fn multiplication(a: i32, b: i32) -> i32 {
pub fn multiplication(a: i32, b: i32) -> i32 {
a * b
}

fn multiplication_print_result(a: i32, b: i32){
pub fn multiplication_print_result(a: i32, b: i32){
println!("{}", multiplication(a, b));
}

mod some_module;

#[allow(unused_variables)]
fn main() {
let x = 2;

Expand Down
6 changes: 3 additions & 3 deletions section_3/3.1/src/some_module.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
pub fn say_hello(){
println!("hello!");
}
pub fn say_hello() {
println!("hello!");
}
13 changes: 12 additions & 1 deletion section_3/3.2/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
# Generated by Cargo
# will have compiled files and executables
debug/
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
Cargo.lock

# These are backup files generated by rustfmt
**/*.rs.bk

# MSVC Windows builds of rustc generate these, which store debugging information
*.pdb
2 changes: 1 addition & 1 deletion section_3/3.2/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ authors = ["TheAdnan <adnankicin92@gmail.com>"]
path= "src/some_crate"

[dependencies]
regex = "0.2.9"

13 changes: 12 additions & 1 deletion section_3/3.3/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
# Generated by Cargo
# will have compiled files and executables
debug/
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
Cargo.lock

# These are backup files generated by rustfmt
**/*.rs.bk

# MSVC Windows builds of rustc generate these, which store debugging information
*.pdb
2 changes: 1 addition & 1 deletion section_3/3.3/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ authors = ["TheAdnan <adnankicin92@gmail.com>"]
path= "src/some_crate"

[dependencies]
regex = "0.2.9"

23 changes: 11 additions & 12 deletions section_3/3.3/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
extern crate some_crate;

#[test]
fn test_user_structure(){
let new_user = some_crate::User{
name: "Dave".to_string(),
email: "dave@mail.com".to_string(),
age: 32,
user_type: some_crate::UserType::Guest
fn test_user_structure() {
let new_user = some_crate::User {
name: "Dave".to_string(),
email: "dave@mail.com".to_string(),
age: 32,
user_type: some_crate::UserType::Guest,
};

assert_eq!("Dave".to_string(), new_user.name);
}

fn main() {

let new_user = some_crate::User{
name: "Dave".to_string(),
email: "dave@mail.com".to_string(),
age: 32,
user_type: some_crate::UserType::Guest
let new_user = some_crate::User {
name: "Dave".to_string(),
email: "dave@mail.com".to_string(),
age: 32,
user_type: some_crate::UserType::Guest,
};

new_user.print_user();
Expand Down
30 changes: 16 additions & 14 deletions section_3/3.3/src/some_crate/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
#[derive(Debug)]
pub struct User{
pub name: String,
pub email: String,
pub age: u16,
pub user_type: UserType
pub struct User {
pub name: String,
pub email: String,
pub age: u16,
pub user_type: UserType,
}

impl User{
pub fn print_user(self){
println!("The name of the user is {}.\nHis email is: {}.\nHe is {} old.\nType of user: {:?}", self.name, self.email, self.age, self.user_type);
}
impl User {
pub fn print_user(self) {
println!(
"The name of the user is {}.\nHis email is: {}.\nHe is {} old.\nType of user: {:?}",
self.name, self.email, self.age, self.user_type
);
}
}

#[derive(Debug)]
pub enum UserType{
Guest,
Regular,
Admin
pub enum UserType {
Guest,
Regular,
Admin,
}

13 changes: 12 additions & 1 deletion section_3/3.4/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
# Generated by Cargo
# will have compiled files and executables
debug/
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
Cargo.lock

# These are backup files generated by rustfmt
**/*.rs.bk

# MSVC Windows builds of rustc generate these, which store debugging information
*.pdb
2 changes: 1 addition & 1 deletion section_3/3.4/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ authors = ["TheAdnan <adnankicin92@gmail.com>"]
path= "src/some_crate"

[dependencies]
regex = "0.2.9"

Loading