Skip to content

Commit

Permalink
Added
Browse files Browse the repository at this point in the history
- Modules Examples 
- Missing Struct definition
  • Loading branch information
ramagururadhakrishnan authored May 7, 2024
1 parent 088d572 commit 2efd78e
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions Assets/Lectures/RL4.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@

### Structures
```
struct Employee {
id: u32,
name: String,
department: String,
}
fn main() {
let employee1 = Employee {
id: 44,
Expand All @@ -26,6 +31,11 @@ fn main() {
```

```
struct Employee {
id: u32,
name: String,
department: String,
}
fn main() {
let mut employee = Employee {
id: 44,
Expand All @@ -40,6 +50,11 @@ fn main() {
```

```
struct Employee {
id: u32,
name: String,
department: String,
}
fn create_employee(id: u32, name: String, department: String) -> Employee {
Employee {
id,
Expand All @@ -54,3 +69,32 @@ fn main() {
println!("Employee ID: {}, Name: {}, Department: {}", employee.id, employee.name, employee.department);
}
```

### Modules

```
// src/main.rs
mod math; // Import the math module
fn main() {
let result_add = math::add(5, 3);
let result_subtract = math::subtract(10, 7);
println!("Addition Result: {}", result_add);
println!("Subtraction Result: {}", result_subtract);
}
```

```
// src/math.rs
pub fn add(a: i32, b: i32) -> i32 {
a + b
}
pub fn subtract(a: i32, b: i32) -> i32 {
a - b
}
```

0 comments on commit 2efd78e

Please sign in to comment.