back to home

I'm Learning Rust

01 Sep 2023

Goren Barak

I’ve decided to learn Rust. Before I decided this, I didn’t know much about the language. I thought it was like all other languages starting with the letter “R”: obscure, but somehow everyone knows about it. A good example of this is R, some obscure statistics language that you should just use scipy or numpy instead of.
I found this to be incorrect. Somehow, although Rust is intuitive, and feels a bit like a high-level language, it also gives you fine-grained control over what the computer does and the memory, in addition to being memory safe and either outperforming C/C++ dramatically or being as fast as it. Let me show you some code, as an example.

My Example

In C, a struct cannot have methods. Rust does not have these limitations. Here is some code to use if you want to make a structure (with methods). It does seem long, but I just added too many comments.

// Define a `Person` structure
struct Person {
	name: String,
	age: u8,
}
// Add a some properties and methods
impl Person {
	// New method
	fn new(name: &str, age: u8) -> Person {
		// The `String::from()` part converts the default &str object to a
		// String object.
		Person {name: String::from(name), age: age}
	} 
}

fn main() {
	// Create a new `Person` object for John Doe
	let john = Person::new("John Doe", 19);
	// Print John's information
	println!("Name: {}\nAge: {}", john.name, john.age)
}

Why I Learned Rust

This isn’t going to be about why I decided, at first, to learn Rust, because that would be a story, and not solid reasons (conversation with someone at Boda Borg). I’m going to explain to why I kept learning Rust. After I had tried at first, I had two choices. I could stop learning Rust, or I could keep learning Rust.
I decided to keep learning Rust because I liked the syntax. I liked the speed. I liked the community. I liked it all. It felt like a breath of fresh air: a syntax more intuitive than Python, JavaScript, or C, yet still faster.

Conclusion

In summary, I’m learning Rust because I love Rust. I love everything about Rust (except the Foundation’s copyright policy, but maybe that’s for another blog post).