My First week learning Rust using (The Rust Programming Language) "The Book"
Why Rust?
As a Front-End developer, there is a ...
For further actions, you may consider blocking this person and/or reporting abuse
In some ways this perspective — fuelled by the chosen syntax — is bound to create confusion later.
When it comes to Rust train your brain ASAP to make the following automatic substitutions:
i.e. "shared" values cannot be mutated and "exclusive" values cannot be "shared".
The immutable ⟷ mutable tension is only a consequence of the primary shared ⟷ exclusive tension.
By default values are assumed to have shared access and therefore have to be explicitly marked for exclusive access (
mut
).See
Nice thank you the tips, specially that link about ownership is a lot at first
You're just in time, implicit named capture is already available in nightly/unstable!
format!(" Hello {name}!");
is indeed coming to stable Rust really soon.I have build a very simple, console hello world program using Rust, Go and C++ on Windows. The executable file size is surprising to me :
Rust is 4Mb, Go is about 3Mb, while C++ is only 171kb (as expected). For C++ I use g++ compiler. I installed Rust using its GNU version of Msi installer.
Can you explain why ?
When I have developed a relatively large web app using PHP+Laravel in backend as well as React, Bootstrap and other 3rd party libs in frontend that has a lot of forms, the bundle size was about 8Mb which I thought was very big. I couldn't use code-splitting at that time.
Now, seeing the 3-4Mb for a console hello world that basically only has one printLn using both Rust and Go seems to be unacceptable.
I don't know about Go, so I can't speak for that. With Rust, you're seeing these sizes due to static linking, and symbols being included in the binary. On Linux, a
hello-world
compiled with--release
generates a 3.7M executable. Just runningstrip
on this executable reduces the size to 310k. You can also se size-related optimizations in your profile:Other tweakables include panic behavior - you can remove the unwinding mechanism using this:
So, yes, while the defaults produce some hefty executables, Rust does expose tools to more finely tweak your result. This repo provides a much more comprehensive overview.
Thanks for the answer. This is just a start for my journey of Rust. I have a plan to try it for web backend after reading your post about it. We know that the book also has a chapter on web server that I can use for starting point.
Quote
Minimizing Rust Binary Size
With C/C++ knowledge Programming Rust 2e may be a better starting point — though if that knowledge is spotty, it could still become a hard slog.
TinyGo - Go compiler for small places
FYI: Zig
Thanks for the explanation, sir.
It is interesting how Rust implements OOP, specifically how it defines a method. Now it reminds me of Go, being a non-OOP language, how it defines a method using a receiver argument which can be a pointer.
Rust is not a fully OOP or even not OOP when using certain definition, unlike C++, Java or C# which are fully OOP. But I like when it provides Struct that we have known in C/C++ and also find in Go. And it provides pointer and smart pointer too. This is why I think, if I have time, I can learn Rust, Go and C++ (relearn) in the same week. :)
Yes, I was reading about it, it will be cool, makes it more inuitive 😃
When I read the book the 1s time, one thing I wanted to know whether Rust provided similar kind of pointers that C/C++ had, or how it managed memory. Then I found one new concept : Ownership which was interesting. But I stopped reading the documentation/book because of other priorities, knowing that it would take long time to learn.
Whenever I think to learn Rust, though, I also remember C++ which I want to re-learn in the correct way using Stanley Lippman's book (C++ Primer).
Ideally, I want to manage my time to learn Rust and C++. I have installed GCC compiler for writing C++ code. I expect I can install Rust which can use GNU compiler instead of MSVC.
I am actuall at the part with owneship, and I found it a bit confusing, since this is my first time learning a low level language, I never really had to think about these factors. But it is definetely interesting to learn about it, I have seen that just with everything theres a trade-off though
Hi Enyel, can you share Practicum discount code with me? I'm interested in their web dev course. Thank you!
Hello, yes. Just saw your message if you have twitter please message me there enyelsequeira