Skip to content

Commit 69d5f7c

Browse files
committed
feat: add first part of lifetimes
1 parent 8a308af commit 69d5f7c

File tree

4 files changed

+35
-1
lines changed

4 files changed

+35
-1
lines changed

Cargo.toml

+4
Original file line numberDiff line numberDiff line change
@@ -97,3 +97,7 @@ path = "Experiments/NatuurkundeModellen/NatuurkundeModellen.rs"
9797
[[bin]]
9898
name = "GenericTypesTraitsLifetimes"
9999
path = "Experiments/GenericTypesTraitsLifetimes/GenericTypesTraitsLifetimes.rs"
100+
101+
[[bin]]
102+
name = "Lifetimes"
103+
path = "Experiments/Lifetimes/Lifetimes.rs"

Experiments/Lifetimes/Lifetimes.rs

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#![allow(non_snake_case)]
2+
mod OutOfScope;
3+
4+
/// lifetimesmsmsmsms
5+
fn main() {
6+
// OutOfScope::main();
7+
}

Experiments/Lifetimes/OutOfScope.rs

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
pub fn main() {
2+
let r;
3+
4+
{
5+
let x = 5;// WE create x that will be dropped later.
6+
r = &x; // We create a reference to x.
7+
// Because x gets out of scop, the reference to it (which is stored in r) becomes broken. x doesn't live long enough.
8+
}
9+
10+
println!("r: {}", r);
11+
}

README.md

+13-1
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,16 @@ Make sure Cargo.toml stays tidy as the script will append the new experiment to
2323
I'm learning Rust because I want to learn a new language.
2424
I see C being used a lot, and I want to learn a language that is similar to C, but with more modern features.
2525
I also want to learn a language that has a good package manager and build system, and has a vibrant community.
26-
Rust seems to mark all the boxes.
26+
Rust seems to mark all the boxes.
27+
28+
29+
## Resources:
30+
31+
* [The Rustonomicon](https://doc.rust-lang.org/nomicon/)
32+
*The Rustonomicon digs into all the awful details that you need to understand when writing Unsafe Rust programs.*
33+
* [Rust by Example](https://doc.rust-lang.org/rust-by-example/)
34+
*Rust by Example (RBE) is a collection of runnable examples that illustrate various Rust concepts and standard libraries.*
35+
* [The Rust Programming Language Book](https://doc.rust-lang.org/book/)
36+
*The Rust Programming Language is the official book about Rust, made by everyone.*
37+
* [Rustlings](https://rustlings.cool/)
38+
*Small exercises to get used to reading, writing and debugging Rust code.*

0 commit comments

Comments
 (0)