Compare commits
4 Commits
7b9aad5fc8
...
develop
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d7d02a4935 | ||
|
|
1d8a7faddf | ||
|
|
2069c2d469 | ||
|
|
ca2c8bdcc6 |
7
containers/Cargo.lock
generated
Normal file
7
containers/Cargo.lock
generated
Normal file
@@ -0,0 +1,7 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 4
|
||||
|
||||
[[package]]
|
||||
name = "containers"
|
||||
version = "0.1.0"
|
||||
6
containers/Cargo.toml
Normal file
6
containers/Cargo.toml
Normal file
@@ -0,0 +1,6 @@
|
||||
[package]
|
||||
name = "containers"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
32
containers/src/main.rs
Normal file
32
containers/src/main.rs
Normal file
@@ -0,0 +1,32 @@
|
||||
enum Direction
|
||||
{
|
||||
Up,
|
||||
Down,
|
||||
Left,
|
||||
Right
|
||||
}
|
||||
|
||||
enum Status
|
||||
{
|
||||
Succeeded(String),
|
||||
Failed(String)
|
||||
}
|
||||
|
||||
fn main() {
|
||||
// normal Enum
|
||||
let direction = Direction::Down;
|
||||
match direction {
|
||||
Direction::Up => println!("Going up"),
|
||||
Direction::Down => println!("Going down"),
|
||||
Direction::Left => println!("Going left"),
|
||||
Direction::Right => println!("Going right"),
|
||||
}
|
||||
|
||||
// enum holding data
|
||||
let status = Status::Failed(String::from("Authentication Failed"));
|
||||
match status
|
||||
{
|
||||
Status::Succeeded(message) => println!("Succeeded with msg: {}",message),
|
||||
Status::Failed(message) => println!("Failed with msg: {}",message),
|
||||
}
|
||||
}
|
||||
@@ -86,4 +86,24 @@ fn main() {
|
||||
{
|
||||
println!("for loop including: {}",x);
|
||||
}
|
||||
|
||||
//functions
|
||||
custom_func();
|
||||
say_name("John Cena");
|
||||
println!("{}", sum(1,5));
|
||||
}
|
||||
|
||||
fn custom_func()
|
||||
{
|
||||
println!("custom func");
|
||||
}
|
||||
|
||||
fn say_name(name: &str)
|
||||
{
|
||||
println!("my name is: {}",name);
|
||||
}
|
||||
|
||||
fn sum(number1 : i32, number2 : i32) -> i32
|
||||
{
|
||||
return number1 + number2;a
|
||||
}
|
||||
7
ownership/Cargo.lock
generated
Normal file
7
ownership/Cargo.lock
generated
Normal file
@@ -0,0 +1,7 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 4
|
||||
|
||||
[[package]]
|
||||
name = "ownership"
|
||||
version = "0.1.0"
|
||||
6
ownership/Cargo.toml
Normal file
6
ownership/Cargo.toml
Normal file
@@ -0,0 +1,6 @@
|
||||
[package]
|
||||
name = "ownership"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
34
ownership/src/main.rs
Normal file
34
ownership/src/main.rs
Normal file
@@ -0,0 +1,34 @@
|
||||
fn main() {
|
||||
let a ="Hello".to_string();
|
||||
let b = a;
|
||||
|
||||
//println!("{}",a); This will error because a no longer owns the string
|
||||
println!("{}",b);
|
||||
|
||||
//simple types like number characters and booleans are copied not moved
|
||||
let c = 5;
|
||||
let d = c;
|
||||
println!("{}",c);
|
||||
println!("{}",d);
|
||||
|
||||
// when ownership does not need to be moved clone can be used.
|
||||
let e ="Test".to_string();
|
||||
let f = e.clone();
|
||||
|
||||
println!("{}",e);
|
||||
println!("{}",f);
|
||||
|
||||
// references in cpp is called borrowing in rust
|
||||
let g = String::from("Reference test");
|
||||
let h = &g;
|
||||
|
||||
println!("{}", g);
|
||||
println!("{}", h);
|
||||
|
||||
// mutable references
|
||||
let mut i = String::from("Mutable Reference test");
|
||||
let j = &mut i;
|
||||
j.push('!');
|
||||
|
||||
println!("{}", j);
|
||||
}
|
||||
@@ -11,6 +11,10 @@ fn main() {
|
||||
let height: f64 = 1.79;
|
||||
let character: char = 'M';
|
||||
let has_driver_license: bool = true;
|
||||
let mut text = "Hello".to_string();
|
||||
text.push_str(" World");
|
||||
let text2 = String::from("Hello world2");
|
||||
println!("{} {}",text,text2);
|
||||
|
||||
//make them mutable by mut modifier
|
||||
let mut middle_name = "Levy";
|
||||
|
||||
Reference in New Issue
Block a user