Skip to content
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
3 changes: 3 additions & 0 deletions live-session/week-6/soroban-hello-world/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@ target
# Local settings
.soroban
.stellar

/test_snapshots
/target
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[package]
name = "Wilfred_Adzer_Basic_Arithmetics_In_Rust"
version = "0.1.0"
edition = "2024"

[dependencies]
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
RUST BOOK

Chapter three
Scalar types are types that represent a single value
-Integers : - They represent a whole number and not part of a whole so they are called numbers without a fractional component, they can be unsigned or signed integers, the isize and usize types of integers depends on the computer arch you are running on
-Floating point numbers
-Booleans
-Characters

Compound Types can group multiple types into one type, rust has two primitive compound types arrays and tuples
- Tuple types - Ways of grouping together a number of values with variety of types into one compound type. tuples have a fixed length once declared cannit grow or shrink in size

fn main() {
let tup: (i32, f64, u8) = (500, 6.4, 1);
}
you can access vales in a tuple using the indexes of the value assigned to the tuple

- Arrays - Elements in an array must be of the same type, arrays in rust have a fixed length
fn main() {
let a = [1, 2, 3, 4, 5];
}
Arrays are used when you are dealing with fixed data types or when you knoe the data will not grow or shrink
let months = ["January", "February", "March", "April", "May", "June", "July",
"August", "September", "October", "November", "December"];
let a: [i32; 5] = [1, 2, 3, 4, 5];

Arrays are used when you want your data to be allocated on a stack

Accessing Array Elements

An array is a single chunk of memory of a known, fixed size that can be allocated on the stack. You can access elements of an array using indexing, like this:

fn main() {
let a = [1, 2, 3, 4, 5];

let first = a[0];
let second = a[1];
}

Functions
The main.rs is the entry point to a rust program
Functions are a set of instructions given to a program to execute and bring forth outputs

We define a function in Rust by entering the fn keyword followed by a function name and a set of parentheses. The curly brackets tell the compiler where the function body begins and ends.


Statements are instructions that perform some action and do not return a value.
Expressions evaluate to a resultant value. Let’s look at some examples.
In rust you have to state the type of return a value a function is expecting



OWNERSHIP
Ownership is a set of rules that govern how rust manages memory

The stack and the heap
Code uses both the stack and heap memory at runtime
Data added to a stack is done in an orderly fashion, data is pilled on top of another and when data is to be accessed on the stack it is done by the last in first out fashion. Data stored on the stack must be fixed sized data and must be known

Data stored on the heap is less organized and does not need to have a fixed size, when a data is to be stored on a heap the memory allocator finds an empty space on the heap marks it as in use and returns the address of that location. The pointer is stored on the stack because it is fixed and known, the data is pushed to the heap and the pointer to the location of the data is stored on the stack

Understanding memory management is key to understanding how the rust programing language works

When your code calls a function, the values passed into the function (including, potentially, pointers to data on the heap) and the function’s local variables get pushed onto the stack. When the function is over, those values get popped off the stack.

Ownership Rules

Each value in Rust has an owner.
There can only be one owner at a time.
When the owner goes out of scope, the value will be dropped.


Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
pub fn add(a: u64, b:u64)-> u64 {
a + b
}


pub fn sub(a:u64, b:u64) -> u64 {
a - b
}


pub fn mul(a:u64, b:u64) -> u64 {
a * b
}


pub fn div(a:u64, b:u64)-> u64 {
a/b
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
mod Operation;

fn main() {

let a = 10;
let b = 5;




println!("Addition: {a} + {b} = {}", Operation::add(a,b));
println!("Subtraction: {a} + {b} = {}", Operation::sub(a,b));
println!("Multiplication: {a} + {b} = {}", Operation::mul(a,b));
println!("Division: {a} + {b} = {}", Operation::div(a,b));


}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"rustc_fingerprint":11283209983122246465,"outputs":{"17747080675513052775":{"success":true,"status":"","code":0,"stdout":"rustc 1.85.0 (4d91de4e4 2025-02-17)\nbinary: rustc\ncommit-hash: 4d91de4e48198da2e33413efdcd9cd2cc0c46688\ncommit-date: 2025-02-17\nhost: x86_64-unknown-linux-gnu\nrelease: 1.85.0\nLLVM version: 19.1.7\n","stderr":""},"13331785392996375709":{"success":true,"status":"","code":0,"stdout":"___\nlib___.rlib\nlib___.so\nlib___.so\nlib___.a\nlib___.so\n/home/wilfred/.rustup/toolchains/stable-x86_64-unknown-linux-gnu\noff\npacked\nunpacked\n___\ndebug_assertions\npanic=\"unwind\"\nproc_macro\ntarget_abi=\"\"\ntarget_arch=\"x86_64\"\ntarget_endian=\"little\"\ntarget_env=\"gnu\"\ntarget_family=\"unix\"\ntarget_feature=\"fxsr\"\ntarget_feature=\"sse\"\ntarget_feature=\"sse2\"\ntarget_has_atomic=\"16\"\ntarget_has_atomic=\"32\"\ntarget_has_atomic=\"64\"\ntarget_has_atomic=\"8\"\ntarget_has_atomic=\"ptr\"\ntarget_os=\"linux\"\ntarget_pointer_width=\"64\"\ntarget_vendor=\"unknown\"\nunix\n","stderr":""}},"successes":{}}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Signature: 8a477f597d28d172789f06886806bc55
# This file is a cache directory tag created by cargo.
# For information about cache directory tags see https://bford.info/cachedir/
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
e08f7436ba7978d7
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"rustc":8277423686421874925,"features":"[]","declared_features":"[]","target":3885547685639333307,"profile":8731458305071235362,"path":4942398508502643691,"deps":[],"local":[{"CheckDepInfo":{"dep_info":"debug/.fingerprint/Wilfred_Adzer_Basic_Arithmetics_In_Rust-f49849a7a125ed57/dep-bin-Wilfred_Adzer_Basic_Arithmetics_In_Rust","checksum":false}}],"rustflags":[],"config":2069994364910194474,"compile_kind":0}
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This file has an mtime of when this was started.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{"$message_type":"diagnostic","message":"module `Operation` should have a snake case name","code":{"code":"non_snake_case","explanation":null},"level":"warning","spans":[{"file_name":"src/main.rs","byte_start":4,"byte_end":13,"line_start":1,"line_end":1,"column_start":5,"column_end":14,"is_primary":true,"text":[{"text":"mod Operation;","highlight_start":5,"highlight_end":14}],"label":null,"suggested_replacement":null,"suggestion_applicability":null,"expansion":null}],"children":[{"message":"`#[warn(non_snake_case)]` on by default","code":null,"level":"note","spans":[],"children":[],"rendered":null},{"message":"convert the identifier to snake case","code":null,"level":"help","spans":[{"file_name":"src/main.rs","byte_start":4,"byte_end":13,"line_start":1,"line_end":1,"column_start":5,"column_end":14,"is_primary":true,"text":[{"text":"mod Operation;","highlight_start":5,"highlight_end":14}],"label":null,"suggested_replacement":"operation","suggestion_applicability":"MaybeIncorrect","expansion":null}],"children":[],"rendered":null}],"rendered":"\u001b[0m\u001b[1m\u001b[33mwarning\u001b[0m\u001b[0m\u001b[1m: module `Operation` should have a snake case name\u001b[0m\n\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12m--> \u001b[0m\u001b[0msrc/main.rs:1:5\u001b[0m\n\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12m|\u001b[0m\n\u001b[0m\u001b[1m\u001b[38;5;12m1\u001b[0m\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12m|\u001b[0m\u001b[0m \u001b[0m\u001b[0mmod Operation;\u001b[0m\n\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12m|\u001b[0m\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[33m^^^^^^^^^\u001b[0m\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[33mhelp: convert the identifier to snake case (notice the capitalization): `operation`\u001b[0m\n\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12m|\u001b[0m\n\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12m= \u001b[0m\u001b[0m\u001b[1mnote\u001b[0m\u001b[0m: `#[warn(non_snake_case)]` on by default\u001b[0m\n\n"}
{"$message_type":"diagnostic","message":"1 warning emitted","code":null,"level":"warning","spans":[],"children":[],"rendered":"\u001b[0m\u001b[1m\u001b[33mwarning\u001b[0m\u001b[0m\u001b[1m: 1 warning emitted\u001b[0m\n\n"}
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/home/wilfred/Projects/Rust_Masterclass/Web3bridge-Rust-Masterclass-Cohort-I/submissions/week-1/day-2/Wilfred_Adzer_Basic_Arithmetics_In_Rust/target/debug/Wilfred_Adzer_Basic_Arithmetics_In_Rust: /home/wilfred/Projects/Rust_Masterclass/Web3bridge-Rust-Masterclass-Cohort-I/submissions/week-1/day-2/Wilfred_Adzer_Basic_Arithmetics_In_Rust/src/Operation.rs /home/wilfred/Projects/Rust_Masterclass/Web3bridge-Rust-Masterclass-Cohort-I/submissions/week-1/day-2/Wilfred_Adzer_Basic_Arithmetics_In_Rust/src/main.rs
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/home/wilfred/Projects/Rust_Masterclass/Web3bridge-Rust-Masterclass-Cohort-I/submissions/week-1/day-2/Wilfred_Adzer_Basic_Arithmetics_In_Rust/target/debug/deps/Wilfred_Adzer_Basic_Arithmetics_In_Rust-f49849a7a125ed57: src/main.rs src/Operation.rs

/home/wilfred/Projects/Rust_Masterclass/Web3bridge-Rust-Masterclass-Cohort-I/submissions/week-1/day-2/Wilfred_Adzer_Basic_Arithmetics_In_Rust/target/debug/deps/Wilfred_Adzer_Basic_Arithmetics_In_Rust-f49849a7a125ed57.d: src/main.rs src/Operation.rs

src/main.rs:
src/Operation.rs:
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
6 changes: 6 additions & 0 deletions submissions/week-6/day-3/Wilfred/todo_project/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Rust's output directory
target

# Local settings
.soroban
.stellar
Loading