Btrust ๐ฆ for Bitcoiners: Week 2 โ It Gets Tougher
Week Two Task Reflection
Btrust ๐ฆ for Bitcoiners: Week 2 โ It Gets Tougher
Week Two Task Reflection

week two task email
BTCdemy taught me a lot this past week. I had to do some extra research to really understand some of the concepts, but it was worth it. Hereโs my personal take on Diving Deeper into Rust using the BTCdemy platforms.
1. Vectors
A vector is a way of representing a collection of values.
let mut vec = Vec::new();
But an easier and more common way is using the macro:
let mut vec = vec![1, 2];
I also learned how to convert a hex string into a vector. We used the hex crate (hex = "0.4"), and the decode() function helped us convert hex strings into vectors.

2. Enums
Enums allow us to describe a set of possible values (variants) for a given category, where only one variant is valid at a time. Each variant can even hold additional data.
To access a variant inside an enum, we often use match, and we must account for every possible variant. But when there are too many, and we don't want to match all of them, we can use the _ (underscore) as a catch-all for any remaining patterns.

Result Enum
The Result type represents either a success (Ok) or a failure (Err):
Ok(T) holds the successful value.
Err(E) holds the error value.
(Note: T and E are generic types โ they can be any data type.)
The .unwrap() method will return the value inside Ok, but beware โ if it's an Err, your program will panic. Speaking of panics, there's also the panic!() macro, like this:
panic!("Error: something went wrong");
But itโs not user-friendly โ it crashes the program and displays an abrupt error message.
3. Pointers and Slices
All data is kept in memory (RAM) so it can be used and manipulated. In Rust, we deal with two main memory regions:
Stack
The stack is structured. It stores variables and functions in a last-in, first-out (LIFO) order โ like a stack of plates. Itโs fast and efficient but limited in size.
Heap
The heap is unstructured and more flexible. It allows for dynamic memory allocation but is slower to access. When sharing large data between functions, using the heap makes it more efficient โ we simply use a pointer (reference) to where the data is stored.

4. Arrays
The Bitcoin protocol uses little endian format, which affects how arrays and bytes are stored and interpreted. Itโs important when working with data encoding or decoding.
That means the least significant byte comes first. So if you see a hex string like 0x12345678, it would be stored as 78 56 34 12.
Weird at first, but itโs a historical design choice. Rust makes it pretty easy to convert between big endian and little endian with built-in methods.


5. Traits
Traits in Rust are like interfaces โ they define shared behavior.
To use a trait, we often need to bring it into scope. For example:
use std::io::Read;
That Read trait gives types the ability to read bytes from a source. Traits are super useful when you want to write generic code that works on multiple types โ like saying "I donโt care what type this is, as long as it can read!"
Itโs one of those things Iโll probably appreciate more the deeper I go.
6. Mutable References
You canโt have two mutable references to the same data at the same time. Rust makes sure of this at compile time to prevent bugs and data races.
This partโฆ yeah. It took some thinking.
Rust is very strict about how data is shared or changed. And it makes sense โ itโs trying to prevent bugs before they happen.
Here are the golden rules I noted:
- You can have one mutable reference, or multiple shared references, but not both.
- You canโt have two mutable references at the same time.
- You canโt read (
&) and write (&mut) at the same time.
Why? So you donโt end up in a situation where youโre reading old data while itโs being changed. Rust wants us to be intentional about every access to memory.
An example:
let mut vec = vec![1, 2, 3];
for x in &vec { vec.push(*x); // โ Nope! Youโre reading and writing at the same time. }`
This will panic or fail to compile โ Rust says, โNope. Try again.โ
7. Ownership and References
This part really hit me โ understanding ownership is key in Rust. Ownership is one of Rustโs biggest concepts. Every value has one owner โ and only one. You can borrow data by creating references (&value) or mutable references (&mut value), but you have to respect the borrowing rules.
Hereโs the golden rule:
At any given time, you can have either:
i. One mutable reference, or
ii. Multiple shared references โ but not both.
You canโt:
i. Have more than one mutable reference.
ii. Have a mutable and shared reference at the same time.
This ensures that you donโt read data while itโs being modified โ very helpful in avoiding bugs.
For example: You canโt iterate over a vector and modify it at the same time.
This is all about keeping data safe and avoiding unexpected behavior.
- A dangling reference
A dangling reference happens when a reference points to memory that has been freed or is no longer valid. Rust prevents this entirely at compile time.

Thatโs my summary for Week 2. It really gets tougher, but I love the challenge. Rust is strict, but in a way that protects you from yourself โ and I respect that.
๋ฉํ๋ฐ์ดํฐ
- post_id
- b2596552df3a
- slug
- btrust-for-bitcoiners-week-2-b2596552df3a
- url
- https://medium.com/@iamtechhunter/btrust-for-bitcoiners-week-2-b2596552df3a
- canonical_url
- https://medium.com/@iamtechhunter/btrust-for-bitcoiners-week-2-b2596552df3a
- author_url
- https://medium.com/@iamtechhunter
- status
- ok
- fetched_at
- 2026-07-19 06:43:54