ERRATA 8:18 the windows installer is a console installer, not graphical, though you can double-click the installer. (or use winget install -e --id Rustlang.Rustup)
The transition from “your code doesn’t work, figure it out” to “your code doesn’t work, try this to fix it” is so extremely helpful that it halfway defines what makes Rust so great.
Two of my own notes that I think are important. 1: Don't rely on the rust error messages that your IDE gives you. IDEs very often take some pieces of the error message but leave a bunch of details out. Whenever its not immediately obvious what an error is saying, go to the terminal and run `cargo check` or just `cargo c`, and you legit often get help messages as useful as the ones in this video. 2: The compiler isn't always correct. The error messages can be extremely good, but the compiler does not know your intention. It can make a best guess, but its not always what you meant.
"The compliner doesn't know your intention" Yeah, fair enough, but honestly, even then I find these error messages pretty useful. Sure it might not be helpful ALL the time, but at least it's more helpful than the stuff I'd get from Python.
Interestingly new python errors (3.10 onwards I think) have started to look like rust. Multiline outputs with specifically pointy underlines it wants you to fix.
Most of the time (but not always for sure), rust-analyzer catches -stupid- obvious mistakes and suggests valid solutions for them. One of the best LSP servers I've ever used, across all languages.
As someone who started coding earlier this year and mostly worked with TypeScript, this honestly makes Rust sound a lot more interesting than I previously thought. JS frameworks have gotten me so used to useless error messages that having the compiler itself tell me what's actually wrong feels like a breath of fresh air.
Rust is so good at turning runtime errors into compile time errors, I often won't run tests until I'm several hours into a project, and somehow it still works right first time (unless I forgot a todo!())
@@NoBoilerplate I got started with Rustlings yesterday and am continuing it this weekend. Honestly, I'm very impressed with it! Whenever I felt I didn't really know what to do, the hints were pretty helpful, as was the Rust book. I wish more languages had something similar to teach you their syntax and unique features, I love this hands-on approach.
If you’re in the client scripting space you might want to look at Elm, which has similar error messages. In fact I think Rust May have learnt this from Elm. Even if you can’t or have no intention of using Elm it’s worth looking at it once. We often learn from other tech even if we never actually use it directly.
As a python TA in college I feel that a good chunk of my job is reading error messages with students, that moment of realization is great. But this feels like a whole other level.
As someone who struggled with not just Rust but programming in general for a good while I find your videos second to none. I feel you don't just show how something is done, but also why you do it. Your videos helped me shake off bad habits, one of them being ignoring error messages. I must also say you just are a great lecturer, you can break down complex topics in super understandable language without compromising on info. Something I really admire. Great video as always. ❤
I love this modern language design decision of having the language itself instruct the programmer. Elm does this spectacularly, and I'm excited to try it out in a lower-level language like Rust.
Great news! Though contrary to what most people will tell you, Rust isn't JUST a low-level language, it's also higher-level than Elm. Check out my video on this here ruclips.net/video/PuMXWc0xrK0/видео.html ALSO if you love elm, you might like Yew, which as the name suggests in inspired by Elm: yew.rs
I've been trying to learn rust on and off for a month now, your channel is really helpful, the videos are fast, straight to the point, and simply amazing.
This video reminds me of something my math teacher once told me: "my pen is smarter than I am". She meant that by writing down what I know about a problem, I give myself help by being able to see the problem one step further along. Helpful error messages are the unsung heroes of programming.
I've been doing Advent of Code using Rust because your series inspired me. I was kind of nervous picking up a systems language* because I made the mistake of trying to learn coding initially via C++. I've got a few years professional experience using JS, Python, and PHP now and have found learning Rust to be a delightful challenge. Keep up the excellent work!
Fantastic! Don't forget to .clone() if you get in a pickle, the performance hit will be *fine*. What did I say about it not being a systems language :-P Ok, I guess more accurately, is it's a universal language - systems AND high-level. Good going! come chat to me and the community on my discord server, there's an advent of code thread!
@@Shnugs haha yup! I started out researching how to do trees in rust. with ownership and no null pointers and everything it seemed difficult. then I gave up and continued reading the book instead :)
Also very nice to use cargo clippy once in a while or use it in CI for bigger projects. It feels like a code review, only you don't need to wait for someone to actually do a code review :D Often with really nice code styling suggestions.
I am a javascript web developer (with some small knowledge of python and php). Just started learning rust and IT IS INCREDIBLE. A whole another world coming from javascript.
The errors you get from `cargo check` are better than the ones rust-analyzer gives you because the window that pops up when you hover over a red squiggly has less formatting than the console, which is a feat.
Agreed, and `cargo clippy` even better! I run clippy in a separate window, even when I use my IDE, using crates.io/crates/bacon Check out my 'lighsaber' video for more info on my toolkit
Errors are also not always clear (for new people). I had a fight with "Futures" error and it turns out that the only thing you needed to do was to add ".await" The "borrowing" is also a big fight I once in a while have. In a lot of cases it is a trial and error until it compiles. Then you wonder what I did wrong and in the end Rust compiler is right all along. It is showing me potential errors I am not even aware of.
Started coding in Rust yesterday. I'm working on the PNGme practice project. The compiler doesn't make coding as easy as this video makes it seem. The compiler keeps on giving me weird errors about Boxes, Dyn, etc, and most of the time doesn't spoonfeed me the answers like I was expecting. Plus, I'm struggling with using iterators. Also, there's a lot of nuances to the language, like when to use into_iter or iter, when to use unwrap or expect or the ? operator. The only thing that keeps me going is knowing that this is way easier than C++, yet just as performant. I struggled with CMake, Dlls, etc. trying to import the SFML graphics library into a C++ project. Soon, I just decided to give up on it. With Rust, I know that Cargo has my back to make importing and using dependencies a breeze. Plus, I'll never get a SegFault. All I gotta do is keep on going, even when it feels like I'm wasting my time on this
@@NoBoilerplate Hello, I am enjoying Rustlings. I got stuck on the Clippy exercises, but then found out that I just have to compile the exercises to get the Clippy feedback
@@ahuman32478 You've got it! run `rustlings watch` to get the nice feedback (bacon style), and don't forget to run `rustlings lsp` once to set up vscode's hints and such, with Rust Analyzer.
As someone who's still learning programming, I'm happy to say that I haven't gotten into the habit of *only* reading the first line of an error code yet, though I do often duck it if I can't figure out what the rest means, so these error codes in rust seem like a godsend to me!
This is a fantastic demonstration of the help you can get from the rust compiler. Also thanks so much for the link to rustlings - such a great way to learn: by debugging!
I'm not a programmer, but IMHO this is what all compilers should do. Error messaged should have a meaning. Without that It's like a firewalls that logs "I guess someone is attacking your network" or or syslog telling you that "one of your programms stopped working".
Wild that most languages dont, right? I think the langues with the best errors also have a lot of syntax - which makes sense, I think, as that gives more clues to the compiler
I'm 16, always been programming, from scratch to python to C++, but I've always felt that something was missing. You've shown me rust, and it not only feels like the missing piece has found, but a whole other darn contraption
If you are very lucky, you could use JUST RUST for your whole programming career - web, bare-metal chips, and everything in between. I'm hoping to only use Rust, now, for the rest of my career :-)
@@NoBoilerplate Thanks for the reply! I hope to also only use Rust, it's really brilliant. Just wondering, I've been meaning to recreate this simple little scratch game as a rust web game for a little while now, do you have any pointers for me?
@@jumbledfox2098 Oh fun! Yes, though I've not done much game development, whenever I hear "game" and "Rust" in the same sentence, I also hear "Bevy". bevyengine.org/ Come chat on my Discord (noboilerplate.org), there's loads of folks who could help you with it! Tag me and say hi 🙂
I only just bumped into this channel. I been itching a bit to try programming again...and not gonna lie, this is sounding VERY nice. Sure the complier isn't perfect as the comments pointed out...but the fact that the complier at least attemps to help you learn the language is something else
I am now fully tempted to learn Rust like how I learn other languages: Mess with the compiler. And yes, I'm tired with sub-millisecond Java code now. Maybe I'll just finish that feature I was working on and then migrate the whole UFB project to Rust.
You'll have a terrific time. I know what you mean, compiler-driven development is fun, especially so in Rust. Here's my recommendation on how to dive in: ruclips.net/video/ifaLk5v3W90/видео.html
Dude this was an exciting video! I can't wait to watch more like this. I'm currently at my 3rd day(77/94) on the Rustings exercises and It's damn good.
It is like C but without the danger - this is because modern machines can do all that cool analysis without your having to wait an hour for the compiler to strain through. I very much like it; gets me close to the metal where I am playing without the occasional frustration of working out why my foot is smashed up.
@@NoBoilerplate I had a lot of fun back in the day hitting CAMAC interfaces to our particle detectors. But boy could you fall down the hole. Now I'm doing stuff on raspberry PI and I do not have to hobble around anymore. Rust is very clever.
@@NoBoilerplate You need to ask the compiler politely - 'I Really Really want to hit this address' And then you are cooking. Mind you, doing it with C was lots of fun as well. That frisson of fear.
Thanks again for another great video. I feel inspired to mess around in my IDE every time you publish. Having such powerful tools at my disposal really compels me to build something cool. Because Rust is so fast, I almost have the urge to build a program that crunches a ton of numbers on many different threads, just because I can :D
Sometimes having fantastic tools around can provide the inspiration for amazing projects. Woodworkers feel this sometimes, if you have a lathe sitting around in your shop maybe you'll get the idea to turn a gorgeous bowl or vase.
RIGHT! This is how I feel about the Rayon library crates.io/crates/rayon you can make any iter a parellel iterator with par_iter() - WHICH I WANT TO DO NOW!
I remember doing the tutorials from the Rust book and got to the point where they deliberately made an error so the compiler would catch it and as soon as I saw what the compiler spit out I immediately went "okay, I'm sold"
I remember moving from c# to c++ and it was a horrible experience with the compiler and linker, especially template errors and linking. The messages are nearly of no use at all :/
I love the idea of giving rust a completely different language and follow the compiler's error messages to transform it into valid rust. Can you make another video that expands on this idea, but with a less trivial codebase, like 100 lines?
I like your videos so much that I get out of my rss feed to like the video, every time, and read some nice comments. I did Advent of Code 2021 in two weeks last month (I'm might have too much free time though) and doing AoC 2022 🎄 in rust again, the compiler is my buddy.
@@NoBoilerplate Not yet, the error messages in my IDE (Sublime Text) when I save a file (with rust-analyzer I think, I don't remember how I installed it) are usually enough. But I'm gonna try it considering how much you like it.
@@philippecholet9484 I don't think it has any complex dependencies, so you could test it out quite easily with a cargo install. I dive into my toolkit recs here ruclips.net/video/ifaLk5v3W90/видео.html
@@NoBoilerplate I've seen all your videos (hopefully/sadly shorts enough) and this one **multiple** times. I tried bacon since my last comment: I like the "press one SINGLE key to change bacon job", I'll dive into its customization.
I genuinely love Rust's helpful compiler messages, but sometimes its design is still far more difficult than other languages. For example, a few weeks back, I was trying to create a system where struct instances could register one of their FnMut methods with a plugin manager to use it as an event callback if certain criteria were met, but the lifetime requirements sadly got too out of hand for me to implement it in a reasonable amount of time. I'd really appreciate a video explaining how to tackle the more complex (usually lifetime-related) issues that the compiler can give, since although Rust makes the easier parts very easy, it can make complex systems much more challenging to write when you don't know how to tackle these sorts of issues.
clone everything my friend! Though you sound like you know how to do it. In your case, I'd re-consider your design, it sounds like you're working against the compiler - Rust has a way of doing things that is very strict, what we get is compile-time verification of our model, what we lose is the ability to write anything we want. I'm happy with this compromise!
@@NoBoilerplate yeah I think the issue is that I need it to be stateful, so if I'm cloning everything I lose the shared state for all the callbacks associated with one struct
Very much the same as a dojo instructor giving you instant feedback, but they're not a mind reader, so being clear about your intentions helps them give you better feedback. Too bad that it can't tell whether or not I "meant" for the program flow to go one way only for it to go a completely different direction as far as high level program design is concerned.
Wonderful! I felt that way when reading the fasterthanli.me article, I based the video one! Here's my short playlist of the best rust features, and how I recommend learning it: ruclips.net/video/oY0XwMOSzq4/видео.html
One of the big resistance to Rust is the fact that Rust code can look very messy. Full of ".unwrap().unwrap().to_string()." For new developers that look at it, it is scary. And also gives the impression that it produces bloated code hard to maintain. It is hard to convince managers that you are not wasting time but also your fellow developer colleagues. However I did manage to create (currently sloppy code) that can execute 1000 parallel threads to test a web site. Not only did I do this in a faster development cycle than any C# program would, I suddenly have the freedom to go beyond any C# capable code. I develop faster because I trust the Rust compiler to catch any mistakes I make.
This is a very heartening take - I've got plans for a series of videos about how to go from zero to rust, without learning any other languages first. And it's for this exact reason - Rust helps you SO much at the start!
@@ex0ja It might be a few months before I get to it, however make sure you've seen my 'getting started' video for now, I've got my learning recommendations there: ruclips.net/video/2hXNd6x9sZs/видео.html
"You need to add an ampersand here, dummy" - Rust compiler, millions of times a day across the world (I'm exaggerating for comedic effect, the Rust compiler is actually very nice about it)
Rust doesn't guarantee that there are no memory leaks on any piece of code. Leaking memory is entirely safe. You can make a cycle of Rc/Arc You can Box::leak You can Box::into_raw and never get the box again You can mem::forget something that holds any smart pointer All of those are entirely safe operations. It was never the goal of Rust's model to ensure that there are no memory leaks.
That's great news! You'll have no problem learning it, it's very easy to learn. Many of Rust features are shared with Java (such as the Optional type), but Java, by it's complicated nature, can't implement them properly. Try : 1. The Rust Book. 2. Rustlings 3. everything on fasterthanli.me
My main language is java too, and I plan to learn rust too. I had started reading the rust book around a month ago. I finished the chapter 2. and started reading 3. But then I got busy and forgot about that. But now after two of your videos i'm lying in my bed at 23:48 (11:48 pm) and thinking about going back to learning rust tomorrow. Thanks for the hints.
I've been working on designing a system's programming language for a couple of months now, and I have to say your videos made me heavily interested in Rust. Being a long time C programmer who has worked on kernel development, nothing has rocked my understanding of imperative languages and type systems as much as Rust has. The main areas we have identified in our PL design efforts are the type system (classes and oop stuff is a sub category), primitives for pre emptive/cooperative/distributed parallelism, structured programming primitives (loops, branching mostly), error handling, meta programming (generics, macros), syntax + semantics and most importantly increasing cohesion and decreasing inter component coupling. Rust addresses most of these problems so well that we're left wondering if there's still meaningful room for improvement. I would love to discuss these aspects of the language as well as generally, and I would love to know what you think are some shortcomings of Rust and other system's languages you may be familiar with.
I'd love to chat about this too, join my discord (links in video description) and ping me in #programming - there's lots of smart folks who are interested in language design! Here's a tip to start off: Because Rust has a proper lisp-style macro system, you can write your language INSIDE rust, not just USING rust. That way you get all of the language features you love for free (including lsp ide support). Here's an example that might blow your mind: github.com/JunSuzukiJapan/macro-lisp
The one area where big improvements are due in Rust is the implementation of its type system. At the moment, it has some nasty limitations. Do you want to make a trait method const? or async? or use impl in return type? or make async closure? well, too bad, not supported yet.
You're too kind! I've perfected my voice on 11 seasons of my hopepunk/scifi podcast, Lost Terminal, what do you think of it? ruclips.net/video/p3bDE9kszMc/видео.html
Honestly, this is why I have always leaned towards C# and avoided Javascript. It might not have the best explanation of compile errors, but it beats the heck out of everything else I have used. Just started my Rust journey, and I am excited to code again.
You're in for an absolute TREAT Don, make sure you've watched at least this playlist, and my "how to learn rust" video ruclips.net/video/oY0XwMOSzq4/видео.html
Would be good to see some clippy rubbed on this exact example, as part of the video, or a follow-up. By default, it got rid of the unnecessary `return`, but with #![warn(clippy::pedantic, clippy::nursery)], it also told us to accept &str instead. Seems like it hasn't yet been taught to see `format!("hello {name}")` as preferable here, though.
Very correct! I was ignoring a lot of clippy errors during my testing here, in order to get the most bare-bones rust experience, for newbies. I love clippy, and run it with those and many other options inside a `bacon` session, alongside my ide!
Definitely going to have to learn Rust at some point then. I like how useful the errors output by the interpreter in Python are for example, and this is even better. Errors in C++ from my experiences so far are… not very useful by themselves.
You'll have a really great time, here's a little playlist to get up to speed quickly, though I have plenty of videos elsewhere! ruclips.net/video/oY0XwMOSzq4/видео.html
Thank you so much, I'm so pleased with it - I ditched the video I was going to produce this fortnight, and instead did this one - rewriting everything on Tuesday!!
Just found your channel and really appreciate the video's structure! Quick errata, but on 6:58, thats not exactly what we did. We fixed the functions return type, not the type of the argument being passed to it or the argument's type itself. Kindly,
It's insane that even though you *just* told me to actually read the error, my immediate reaction to the first error dump was to not even read the first line properly. This will be a very hard habit to break...
I love how some people say it's a bad thing that Rust does all that, and that "real programmers" don't need it. It's hilarious. Rust also makes it really easy to define and enforce quality standards in your project. In your lib file: #![forbid(unsafe_code)] #![warn(missing_docs)] #![warn(clippy::unwrap_used)] #![warn(clippy::todo)] #![warn(clippy::panic)] Then in your CI: cargo fmt --check --verbose cargo clippy -- -D warnings You can add plenty of other lints (rust-analyzer gives you a list with explanations on what each one does when you start typing). The warn level lets developers take some shortcuts while working with the code locally, but reminds them to clean everything up before pushing. And the pipeline ensures that code doesn't get merged until it's basically flawless. There's also cargo-deny, which searches your dependencies for known vulnerabilities and incompatible licenses. And probably many other tools I don't even know about yet.
@@NoBoilerplate I saw it on one of your previous videos, but I haven't tried it yet. I imagine it gets hard to use when you have lots of dependencies, since most of them do not guarantee that there are no panics, and often you have to turn on optimizations for the panics to be optimized out. I kind of wish there was a keyword for that in the language itself, like unsafe but the other way around ("extra_safe"? IDK), so it would get checked at compile time rather than link time, and maybe more crates would adopt it. But maybe an attribute that keeps you from using basic arithmetic operators on integers or clamp() on floats would be so annoying that no one would bother with it. Who knows...
@@yondaime500 Yeah, we have to draw the line somewhere, for me in normal code I use checked maths and never .unwrap() (enforced with clippy) and then don't worry about oom panics or other rare stuff.
@@NoBoilerplate Ah I see what you mean. Did not realize that they actually mean a different thing. So methods are those attached to structs while functions are not? In any case, you could probably make a clarification for those that are unaware.
Rules for living with Rusts compiler 1. The compiler hurts you because it loves you. 2. The more the compiler hurts you, the more it loves you. 3. Don't fight back, just let it happen. "Remember, the compiler loves you" - No Boilerplate.
I am an absolute begginer into coding, I've started with Python, but than I looked into Rust and your videos are compelling me to learn Rust first. I watched your other video, I started reading the book, but it seems it is not for absolute beginners. I wish you had a course for someone like me with adhd who wants to start with code at 35 years of age.
Imagine if they incorporate an alternative to GitHub copilot to the rust compiler, so that the help will use the power of machine learning similar to copilot that recommend solutions as well based on code it has trained from. Would be interesting to see using that to help you develop using rust too.
@@NoBoilerplate it was just a thought. Would be interesting to maybe get two recommendations, a compiler recommendation and maybe a machine learning recommendation (based on the best code solution it could find) to help you fix an error. Not sure how easy it is to add this directly to a compiler and make it run smoothly, but it was a little idea in my head 😅 Maybe this could be researched to see it's practicality in the real world.
@@NoBoilerplate Sure! I mean, it's a RUclips comment. But on Elm the error messages are even less cryptic. The video shows how to follow the compiler helps us find the solutions to the compilation errors. But on Elm it's spot on! I ran into an unexpected symbol: 27| type alias Model = Int | String ^ I was not expecting to see a | here. Try deleting it? Maybe I can give a better hint from there? Some other: Something is off with the body of the `init` definition: 32| "" ^^ The body is a string of type: String But the type annotation on `init` says it should be: Model LAST EXAMPLE, Check it out This `case` does not have branches for all possibilities: 46|> case msg of 47|> Increment -> 48|> model + 1 49|> 50|> Decrement -> 51|> model - 1 Missing possibilities include: SomethingElse I would have to crash if I saw one of those. Add branches for them! Hint: If you want to write the code for each branch later, use `Debug.todo` as a placeholder. Read for more guidance on this workflow. You can just elm-lang.org/examples/buttons and fiddle around making compilation fail somehow by experimenting. Its more straightforward
and that being said, both are very different, Elm is for a very narrow context: web applications. Rust is way more flexible. Having working a lot with Elm, I do think it's similar to how Rust works in some areas like error handling. Compiler messages are just friendlier and easier to read
The compiler being happy doesn’t mean there are no memory leaks. Box::leak is safe, although it makes it obvious that memory is being leaked. But, creating an Rc cycle will also leak memory and might well be accidental
@@NoBoilerplate Well it's easy if you want to leak it (which is good, it's sometimes useful). I think it really depends on the abstraction you use, if you use the Rc type to make graphs or other complex shared ownership data structures, especially intrusive ones, you may well encounter some leaks. If you don't then it is quite rare
@@NoBoilerplate I'd say in Rust, memory leaks are as unlikely to happen by accident as in most GC languages. You can do it on purpose with Box::leak. You can do it by accident with Rc-based graphs. But littering Rc liberally is already a red flag, tbh.
Missed opportunity: Follow up by using clippy to make this code more idiomatic. Doesn’t give too much in this particular case, but clippy certainly “teaches” some things really well, too. (It doesn’t help you go all the way in this case; arguably, the argument type of this function should become `&str`, and there’s no compiler or `clippy` telling you, AFAICT.)
Very correct! I was ignoring a lot of clippy errors during my testing here, in order to get the most bare-bones rust experience, for newbies. I love clippy, and run it with those and many other options inside a `bacon` session, alongside my ide!
I have been learning Rust for a while, but not so many companies are willing to try it for their APIs. The general notion is that it's a system language only.
that is what I hope to dispel in my Rust series - Rust is a universal language! Do check out my "turtles" video - I explain how rust is as low-level as C, and as high-level as lisp
I've been playing around with Rust but there's always a point where I run into a compiler error and it can't help me. For example, I needed to edit two elements of an array at the same time. Actually, not the element itself but some sub-variable of them. I couldn't do it, bc of course I can't borrow 2 elements of an array. But I haven't found a solution and I went away for a while. Until I randomly stumbled upon it on RUclips with the name smart pointers. And well, they can become quite complex if you don't know them well. So that's where I'm stuck on currently, learning different types of smart pointers and no the compiler doesn't teach me this sadly.
That sounds tough, but you'll get there I bet! The exciting thing is that the rust language is rich enough that it is possible to improve the errors so much that they'll eventually start suggesting smart pointers!
There are ways to mutably borrow multiple elements form the same slice. This is safe, as long as the elements are distinct. Here's a function that borrows two elements from a slice, or gives an error if indices are equal: fn get_mut_two(source: &mut [T], a: usize, b: usize) -> Result { match a.cmp(&b) { std::cmp::Ordering::Equal => return Err(()), std::cmp::Ordering::Less => { let (beggining, rest) = source.split_at_mut(b); Ok((&mut beggining[a], &mut rest[b])) }, std::cmp::Ordering::Greater => { let (b,a) = get_mut_two(source, b, a)?; Ok((a,b)) }, } } And here's a version that borrows arbitrary N elements from a slice. Though the implementation uses unsafe, and has expensive runtime checks, that are unlikely to be optimized. fn get_mut_n(source: &mut [T], indeces: [usize;N]) -> Result { // check for index out of bounds if indeces.iter().any(|&i| i>=source.len()) { return Err(()) } /// check for duplicate indices let mut sorted_indices = indeces; sorted_indices.sort_unstable(); if sorted_indices.windows(2).any(|w| w[0]==w[1]) { return Err(()) } // SAFETY // indices are all distinct and in bounds unsafe { Ok(indeces.map(|i| &mut *source.as_mut_ptr().add(i))) } }
@@NoBoilerplate you are the reason why I started my journey with rust and now I am doing advent of code with rust. You are literally changing lives ❤️ World is a better place because you exist ❤️
Hi. I've been watching your Rust videos for a while and I want to start programming in Rust now. I installed Rustup and am trying to configure my workspace right now. Rust is asking me to install MSVC build tools, but they're also offering me the option to skip ahead if I'd rather use the GNU ABI. Would you recommend using the MSVC toolchain or go the GNU pathway? I believe that software should be able to support all platforms, so I want to make sure my applications support Windows, Mac, AND Linux
Cross-compilation is trivial in Rust, so you can usually code on one platform, and make binaries for any other platform. I'm uncertain about developing on windows, however, I've heard that it's best to use WSL2, to give a much nicer experience. WSL is really great these days, and will side-step this, and many other issues you'll face learn.microsoft.com/en-us/windows/wsl/install
@@NoBoilerplate Tbh my computer is on the verge of running out of memory, less than 10 gigabytes left. Got no room for a Linux subsystem. But I will take your advice that cross-compilation is easy no matter the platform and use MSVC since it's the recommended toolchain for Windows. Thanks
If the compiler can produce suggestions for what might work instead of what we've written, wouldn't it be easier if we could just press a button to try out if that suggestion works without manually changing our code and another button to accept those changes if they do? Instead of manually trying it out and undoing it if it didn't work.
8:10 ik the link is on screen but would be nice to have it on description/on the pinned comment so people can find it(if they got low vision/blindness/any other reason) too :)
It's very good tutorial.. but can you do something usefull in the same format from practical meanting for example implement wallet may be add GRPC for show how good / bad rust is for working in real problem scope. Best practices for example. Hello world is good.. but lay huge gap between it and something useful.. like for example spring boot application.
Thank you! Funny story, I had written an entirely different video for today, but on Tuesday I had this brainwave and wrote this video instead! I'm delighted.
Whats your opinion on natural intuitive value on designing distributed concurrent systems when we are forced to choose between rust on one aile(or C++n java on the same aile)and functional programming languages like Haskell,scala on the other side
Don't forget Go - though I think Rust is better than Go, go is still extremely good (though it has a GC, no macros, and no super powers). I'd say Rust has a lot of functional flavour built-in - the original compiler was writtin in ocaml, and even at one point had an functional purity system, though it was removed, as the Result passing convention works so well. You can see the functional influence in both the iterator system, and the monads `Result` and `Option` which are foundational to the Rust standard library and ecosystem.
ERRATA
8:18 the windows installer is a console installer, not graphical, though you can double-click the installer. (or use winget install -e --id Rustlang.Rustup)
8:18 correction: the Windows installer is CLI, not graphical, although it can be launched with a simple double click.
Btw RUclips offered to translate this comment into "ERRATUM all!()" which was funny
@@scheimong oh that's fun, thank you I've never tried (I'd use WSL2 probably). Added!
Windows one line installer - if your windows already have winget tool or windows update containing it.
winget install -e --id Rustlang.Rustup
another correction: 6:57 - that is, not, what we did. similar, but not it.
Addendum to "If the compiler is happy, I am happy": "If clippy is happy, I am very happy"
Yes!
Yes! I love running `bacon` (cargo install bacon) in clippy mode alongside my code. This is how I write this videos actually :-)
@@NoBoilerplate bacon is sooooo cool!!!! you can even do bacon run or bacon test!!!
@@NoBoilerplate what in gods name is 🥓
@@dinofrog926 your life is about to level up! crates.io/crates/bacon
I talk about bacon in my 'lightsaber' video, check it out!
Find someone to love you as this guy loves Rust
I mostly love not being paged by work at 4am :-)
Nailed it
Impossible
Your mother?
The transition from “your code doesn’t work, figure it out” to “your code doesn’t work, try this to fix it” is so extremely helpful that it halfway defines what makes Rust so great.
Two of my own notes that I think are important.
1: Don't rely on the rust error messages that your IDE gives you.
IDEs very often take some pieces of the error message but leave a bunch of details out.
Whenever its not immediately obvious what an error is saying, go to the terminal and run `cargo check` or just `cargo c`, and you legit often get help messages as useful as the ones in this video.
2: The compiler isn't always correct.
The error messages can be extremely good, but the compiler does not know your intention.
It can make a best guess, but its not always what you meant.
REALLY good advice here. I often run `bacon` (cargo install bacon) in a terminal alongside my IDE for this reason
"The compliner doesn't know your intention"
Yeah, fair enough, but honestly, even then I find these error messages pretty useful. Sure it might not be helpful ALL the time, but at least it's more helpful than the stuff I'd get from Python.
Interestingly new python errors (3.10 onwards I think) have started to look like rust. Multiline outputs with specifically pointy underlines it wants you to fix.
Bacon jokes aside, do you have a video on Rust bacon?
Most of the time (but not always for sure), rust-analyzer catches -stupid- obvious mistakes and suggests valid solutions for them. One of the best LSP servers I've ever used, across all languages.
I just want to build something one day that someone loves as much as this guy loves rust.
what I really love is *sleep*, and not to be paged at 4am ;-)
@@NoBoilerplate you have a pager?
@@agnishom I *wish*. pagerduty.com calls my phone
crazy how No Boilerplate's videos are the only ones making me more excited to code, even though I like coding already
It's RUST doing it to me! It makes me want to build stuff!
Never seen a compiler so happy while being abused in such terrible ways
Wild, right?!
As someone who started coding earlier this year and mostly worked with TypeScript, this honestly makes Rust sound a lot more interesting than I previously thought. JS frameworks have gotten me so used to useless error messages that having the compiler itself tell me what's actually wrong feels like a breath of fresh air.
Give it a go, try Rustlings!
Rust is so good at turning runtime errors into compile time errors, I often won't run tests until I'm several hours into a project, and somehow it still works right first time (unless I forgot a todo!())
@@NoBoilerplate I got started with Rustlings yesterday and am continuing it this weekend. Honestly, I'm very impressed with it! Whenever I felt I didn't really know what to do, the hints were pretty helpful, as was the Rust book. I wish more languages had something similar to teach you their syntax and unique features, I love this hands-on approach.
@@kochkochkoch I'm going through Rustlings with my team at work and I'm learning something every session too!
If you’re in the client scripting space you might want to look at Elm, which has similar error messages. In fact I think Rust May have learnt this from Elm. Even if you can’t or have no intention of using Elm it’s worth looking at it once. We often learn from other tech even if we never actually use it directly.
As a python TA in college I feel that a good chunk of my job is reading error messages with students, that moment of realization is great. But this feels like a whole other level.
Yeah! Its important in python too, up to the limits of the language. Have you tried mypy?
Python is improving compile errors, inspired by Rust ;-)
Prologue lover?
As someone who struggled with not just Rust but programming in general for a good while I find your videos second to none. I feel you don't just show how something is done, but also why you do it. Your videos helped me shake off bad habits, one of them being ignoring error messages. I must also say you just are a great lecturer, you can break down complex topics in super understandable language without compromising on info. Something I really admire.
Great video as always. ❤
Thank you so much for saying so Della, I really appreciate it! :-)
I love this modern language design decision of having the language itself instruct the programmer. Elm does this spectacularly, and I'm excited to try it out in a lower-level language like Rust.
Great news! Though contrary to what most people will tell you, Rust isn't JUST a low-level language, it's also higher-level than Elm.
Check out my video on this here ruclips.net/video/PuMXWc0xrK0/видео.html
ALSO if you love elm, you might like Yew, which as the name suggests in inspired by Elm: yew.rs
I've been trying to learn rust on and off for a month now, your channel is really helpful, the videos are fast, straight to the point, and simply amazing.
Thank you! If you've not seen it, here's how I recommend you learn Rust ruclips.net/video/2hXNd6x9sZs/видео.html
This video reminds me of something my math teacher once told me: "my pen is smarter than I am". She meant that by writing down what I know about a problem, I give myself help by being able to see the problem one step further along. Helpful error messages are the unsung heroes of programming.
I've been doing Advent of Code using Rust because your series inspired me. I was kind of nervous picking up a systems language* because I made the mistake of trying to learn coding initially via C++. I've got a few years professional experience using JS, Python, and PHP now and have found learning Rust to be a delightful challenge.
Keep up the excellent work!
Fantastic! Don't forget to .clone() if you get in a pickle, the performance hit will be *fine*.
What did I say about it not being a systems language :-P Ok, I guess more accurately, is it's a universal language - systems AND high-level.
Good going! come chat to me and the community on my discord server, there's an advent of code thread!
are we the same person? I am also doing advent of code to learn rust because this guy’s series inspired me! I am currently on day 7 :)
@@dinofrog926 Bruh. Day 7 hit like a truck after 6.
@@Shnugs haha yup! I started out researching how to do trees in rust. with ownership and no null pointers and everything it seemed difficult. then I gave up and continued reading the book instead :)
i cannot believe it knows what other languages look like and can tell you how to translate.
Also very nice to use cargo clippy once in a while or use it in CI for bigger projects.
It feels like a code review, only you don't need to wait for someone to actually do a code review :D Often with really nice code styling suggestions.
Yes! I love running `bacon` (cargo install bacon) in clippy mode alongside my code. This is how I write this videos actually :-)
I am a javascript web developer (with some small knowledge of python and php). Just started learning rust and IT IS INCREDIBLE. A whole another world coming from javascript.
Isn't it lovely! I'm a python webdev and its like a new world!
Also just started learning rust, and I noticed the compiler almost immediately becaus of it's quality. But didn't know it was that good.
so lovely, isn't it!
Thanks to you and @Primeagen, i'm actually learning rust and hoping to port all my production applications to rust!!!
Great Content!!!
He's fantastic too, also check out Code To The Moon!
I often describe the rust compiler as a helpful nanny, walking you through your mistakes and giving suggestions on how to correct them.
Absolutely, in other of my videos I've described it as a driving instructor, helping you navigate the dangerous highway. Similar!
The errors you get from `cargo check` are better than the ones rust-analyzer gives you because the window that pops up when you hover over a red squiggly has less formatting than the console, which is a feat.
Agreed, and `cargo clippy` even better!
I run clippy in a separate window, even when I use my IDE, using crates.io/crates/bacon
Check out my 'lighsaber' video for more info on my toolkit
Errors are also not always clear (for new people).
I had a fight with "Futures" error and it turns out that the only thing you needed to do was to add ".await"
The "borrowing" is also a big fight I once in a while have.
In a lot of cases it is a trial and error until it compiles. Then you wonder what I did wrong and in the end Rust compiler is right all along.
It is showing me potential errors I am not even aware of.
There's work to be done, but its worth it!
this video made me realize that I have some weird deep-rooted fear of reading error messages
Started coding in Rust yesterday. I'm working on the PNGme practice project. The compiler doesn't make coding as easy as this video makes it seem. The compiler keeps on giving me weird errors about Boxes, Dyn, etc, and most of the time doesn't spoonfeed me the answers like I was expecting. Plus, I'm struggling with using iterators. Also, there's a lot of nuances to the language, like when to use into_iter or iter, when to use unwrap or expect or the ? operator.
The only thing that keeps me going is knowing that this is way easier than C++, yet just as performant. I struggled with CMake, Dlls, etc. trying to import the SFML graphics library into a C++ project. Soon, I just decided to give up on it. With Rust, I know that Cargo has my back to make importing and using dependencies a breeze. Plus, I'll never get a SegFault. All I gotta do is keep on going, even when it feels like I'm wasting my time on this
Pause right now and complete Rustlings, then go back. My recs here: ruclips.net/video/2hXNd6x9sZs/видео.html
@@NoBoilerplate Hello, I am enjoying Rustlings. I got stuck on the Clippy exercises, but then found out that I just have to compile the exercises to get the Clippy feedback
@@ahuman32478 You've got it! run `rustlings watch` to get the nice feedback (bacon style), and don't forget to run `rustlings lsp` once to set up vscode's hints and such, with Rust Analyzer.
As someone who's still learning programming, I'm happy to say that I haven't gotten into the habit of *only* reading the first line of an error code yet, though I do often duck it if I can't figure out what the rest means, so these error codes in rust seem like a godsend to me!
They really are!
This is a fantastic demonstration of the help you can get from the rust compiler. Also thanks so much for the link to rustlings - such a great way to learn: by debugging!
I'm not a programmer, but IMHO this is what all compilers should do. Error messaged should have a meaning.
Without that It's like a firewalls that logs "I guess someone is attacking your network" or or syslog telling you that "one of your programms stopped working".
Wild that most languages dont, right? I think the langues with the best errors also have a lot of syntax - which makes sense, I think, as that gives more clues to the compiler
I'm 16, always been programming, from scratch to python to C++, but I've always felt that something was missing. You've shown me rust, and it not only feels like the missing piece has found, but a whole other darn contraption
If you are very lucky, you could use JUST RUST for your whole programming career - web, bare-metal chips, and everything in between. I'm hoping to only use Rust, now, for the rest of my career :-)
@@NoBoilerplate Thanks for the reply! I hope to also only use Rust, it's really brilliant. Just wondering, I've been meaning to recreate this simple little scratch game as a rust web game for a little while now, do you have any pointers for me?
@@jumbledfox2098 Oh fun! Yes, though I've not done much game development, whenever I hear "game" and "Rust" in the same sentence, I also hear "Bevy".
bevyengine.org/
Come chat on my Discord (noboilerplate.org), there's loads of folks who could help you with it! Tag me and say hi 🙂
@@NoBoilerplate Thank you!
@@jumbledfox2098did you just say… POINTERS?
I only just bumped into this channel. I been itching a bit to try programming again...and not gonna lie, this is sounding VERY nice. Sure the complier isn't perfect as the comments pointed out...but the fact that the complier at least attemps to help you learn the language is something else
Check out the rest of my Rust videos, I have them in a playlist, and then get cracking with The Book doc.rust-lang.org/stable/book/
I am now fully tempted to learn Rust like how I learn other languages: Mess with the compiler.
And yes, I'm tired with sub-millisecond Java code now.
Maybe I'll just finish that feature I was working on and then migrate the whole UFB project to Rust.
You'll have a terrific time. I know what you mean, compiler-driven development is fun, especially so in Rust.
Here's my recommendation on how to dive in: ruclips.net/video/ifaLk5v3W90/видео.html
Dude this was an exciting video! I can't wait to watch more like this. I'm currently at my 3rd day(77/94) on the Rustings exercises and It's damn good.
Nice! I love rustlings so much. Have you seen my whole Rust series? ruclips.net/video/Q3AhzHq8ogs/видео.html
Yes, some of them. The more I learn about Rust, the more I like them 😃
It is like C but without the danger - this is because modern machines can do all that cool analysis without your having to wait an hour for the compiler to strain through.
I very much like it; gets me close to the metal where I am playing without the occasional frustration of working out why my foot is smashed up.
Yeah! I'm having so much FUN!
@@NoBoilerplate I had a lot of fun back in the day hitting CAMAC interfaces to our particle detectors. But boy could you fall down the hole.
Now I'm doing stuff on raspberry PI and I do not have to hobble around anymore. Rust is very clever.
@@chrissaltmarsh6777 Cool! I'd love to do bare-metal on the pi
@@NoBoilerplate You need to ask the compiler politely - 'I Really Really want to hit this address' And then you are cooking.
Mind you, doing it with C was lots of fun as well. That frisson of fear.
@@chrissaltmarsh6777 hehe I prefer less fear. I'd never have picked up a language with pointers if it weren't for Rust!
Thanks again for another great video. I feel inspired to mess around in my IDE every time you publish. Having such powerful tools at my disposal really compels me to build something cool. Because Rust is so fast, I almost have the urge to build a program that crunches a ton of numbers on many different threads, just because I can :D
Sometimes having fantastic tools around can provide the inspiration for amazing projects. Woodworkers feel this sometimes, if you have a lathe sitting around in your shop maybe you'll get the idea to turn a gorgeous bowl or vase.
RIGHT! This is how I feel about the Rayon library
crates.io/crates/rayon
you can make any iter a parellel iterator with par_iter() - WHICH I WANT TO DO NOW!
@@NoBoilerplate WHAT!?!? That might just be the coolest crate ever
I started learning Rust with lovely videos made by Tris. Thanks a lot
My pleasure, and thank you! Do join my Discord if you'd like help!
I remember doing the tutorials from the Rust book and got to the point where they deliberately made an error so the compiler would catch it and as soon as I saw what the compiler spit out I immediately went "okay, I'm sold"
This is the way!
I think this is going to be the video that finally gets me to learn rust.
Give it a go! Rustlings is such a great resource to teach through doing
I remember moving from c# to c++ and it was a horrible experience with the compiler and linker, especially template errors and linking. The messages are nearly of no use at all :/
This channel gives me a feeling of love to a low level language like C when I started learning to program, I will go for rust.
Its really incredible isn't it!
These videos are so good. They make Rust even better!
Other way around - rust is so good I am doing everything I can to make it more widely known
I love the idea of giving rust a completely different language and follow the compiler's error messages to transform it into valid rust. Can you make another video that expands on this idea, but with a less trivial codebase, like 100 lines?
I like your videos so much that I get out of my rss feed to like the video, every time, and read some nice comments.
I did Advent of Code 2021 in two weeks last month (I'm might have too much free time though) and doing AoC 2022 🎄 in rust again, the compiler is my buddy.
Fantastic, and thank you very much!
Have you tried bacon? (cargo install bacon) so good for running in a terminal while you code!
@@NoBoilerplate Not yet, the error messages in my IDE (Sublime Text) when I save a file (with rust-analyzer I think, I don't remember how I installed it) are usually enough. But I'm gonna try it considering how much you like it.
@@philippecholet9484 I don't think it has any complex dependencies, so you could test it out quite easily with a cargo install. I dive into my toolkit recs here ruclips.net/video/ifaLk5v3W90/видео.html
@@NoBoilerplate I've seen all your videos (hopefully/sadly shorts enough) and this one **multiple** times.
I tried bacon since my last comment: I like the "press one SINGLE key to change bacon job", I'll dive into its customization.
I genuinely love Rust's helpful compiler messages, but sometimes its design is still far more difficult than other languages. For example, a few weeks back, I was trying to create a system where struct instances could register one of their FnMut methods with a plugin manager to use it as an event callback if certain criteria were met, but the lifetime requirements sadly got too out of hand for me to implement it in a reasonable amount of time. I'd really appreciate a video explaining how to tackle the more complex (usually lifetime-related) issues that the compiler can give, since although Rust makes the easier parts very easy, it can make complex systems much more challenging to write when you don't know how to tackle these sorts of issues.
Yeah lifetimes are not easy. I'm still in the "is the compiler happy with this lifetime change? Or this one?" phase.
clone everything my friend! Though you sound like you know how to do it.
In your case, I'd re-consider your design, it sounds like you're working against the compiler - Rust has a way of doing things that is very strict, what we get is compile-time verification of our model, what we lose is the ability to write anything we want. I'm happy with this compromise!
instead of using references, try .clone()ing everything while you're learning :-D
@@NoBoilerplate yeah I think the issue is that I need it to be stateful, so if I'm cloning everything I lose the shared state for all the callbacks associated with one struct
@@miguelguthridge You, my friend, do not need my help! Come ask in #programming on my discord server if you like, there's some geniuses over here!
Very much the same as a dojo instructor giving you instant feedback, but they're not a mind reader, so being clear about your intentions helps them give you better feedback.
Too bad that it can't tell whether or not I "meant" for the program flow to go one way only for it to go a completely different direction as far as high level program design is concerned.
Agreed, though with sum types (ie, Rust's enums), you can express your intent much better than in languages that don't have sum types!
What a lovely compiler !
99% reason behind my pick on Rust, beside borrow-checker, no GC, high perf and every other nice things.
even macros! What a delightful language.
This video was convincing enough to get me to start learning Rust immediately.
Wonderful! I felt that way when reading the fasterthanli.me article, I based the video one!
Here's my short playlist of the best rust features, and how I recommend learning it: ruclips.net/video/oY0XwMOSzq4/видео.html
One of the big resistance to Rust is the fact that Rust code can look very messy. Full of ".unwrap().unwrap().to_string()."
For new developers that look at it, it is scary. And also gives the impression that it produces bloated code hard to maintain.
It is hard to convince managers that you are not wasting time but also your fellow developer colleagues.
However I did manage to create (currently sloppy code) that can execute 1000 parallel threads to test a web site.
Not only did I do this in a faster development cycle than any C# program would, I suddenly have the freedom to go beyond any C# capable code. I develop faster because I trust the Rust compiler to catch any mistakes I make.
The way I look at it, unwrap()s are for protyping code - take a look at my vide Rust On Rails for my recommendations here
As a beginner I do feel like rust is the easiest language I've tried so far, mainly because of the way cargo works and the errors.
This is a very heartening take - I've got plans for a series of videos about how to go from zero to rust, without learning any other languages first. And it's for this exact reason - Rust helps you SO much at the start!
@@NoBoilerplate I'd greatly appreciate that as that's what I'm doing!
@@ex0ja It might be a few months before I get to it, however make sure you've seen my 'getting started' video for now, I've got my learning recommendations there: ruclips.net/video/2hXNd6x9sZs/видео.html
@@NoBoilerplate yes I have and I'm following your advice, I've just finished Ultralearning yesterday ☺️
"You need to add an ampersand here, dummy" - Rust compiler, millions of times a day across the world
(I'm exaggerating for comedic effect, the Rust compiler is actually very nice about it)
It's so patient!
Rust doesn't guarantee that there are no memory leaks on any piece of code.
Leaking memory is entirely safe.
You can make a cycle of Rc/Arc
You can Box::leak
You can Box::into_raw and never get the box again
You can mem::forget something that holds any smart pointer
All of those are entirely safe operations. It was never the goal of Rust's model to ensure that there are no memory leaks.
I'm a Java dev and I want to learn Rust so badly; it seems like an amazing language.
That's great news! You'll have no problem learning it, it's very easy to learn. Many of Rust features are shared with Java (such as the Optional type), but Java, by it's complicated nature, can't implement them properly.
Try : 1. The Rust Book. 2. Rustlings 3. everything on fasterthanli.me
My main language is java too, and I plan to learn rust too. I had started reading the rust book around a month ago. I finished the chapter 2. and started reading 3. But then I got busy and forgot about that. But now after two of your videos i'm lying in my bed at 23:48 (11:48 pm) and thinking about going back to learning rust tomorrow.
Thanks for the hints.
I've been working on designing a system's programming language for a couple of months now, and I have to say your videos made me heavily interested in Rust. Being a long time C programmer who has worked on kernel development, nothing has rocked my understanding of imperative languages and type systems as much as Rust has.
The main areas we have identified in our PL design efforts are the type system (classes and oop stuff is a sub category), primitives for pre emptive/cooperative/distributed parallelism, structured programming primitives (loops, branching mostly), error handling, meta programming (generics, macros), syntax + semantics and most importantly increasing cohesion and decreasing inter component coupling.
Rust addresses most of these problems so well that we're left wondering if there's still meaningful room for improvement. I would love to discuss these aspects of the language as well as generally, and I would love to know what you think are some shortcomings of Rust and other system's languages you may be familiar with.
I'd love to chat about this too, join my discord (links in video description) and ping me in #programming - there's lots of smart folks who are interested in language design!
Here's a tip to start off: Because Rust has a proper lisp-style macro system, you can write your language INSIDE rust, not just USING rust. That way you get all of the language features you love for free (including lsp ide support). Here's an example that might blow your mind:
github.com/JunSuzukiJapan/macro-lisp
The one area where big improvements are due in Rust is the implementation of its type system. At the moment, it has some nasty limitations.
Do you want to make a trait method const? or async? or use impl in return type? or make async closure? well, too bad, not supported yet.
I love the voice of this guy, now as go programmer i love rust too.
You're too kind! I've perfected my voice on 11 seasons of my hopepunk/scifi podcast, Lost Terminal, what do you think of it? ruclips.net/video/p3bDE9kszMc/видео.html
Honestly, this is why I have always leaned towards C# and avoided Javascript. It might not have the best explanation of compile errors, but it beats the heck out of everything else I have used.
Just started my Rust journey, and I am excited to code again.
You're in for an absolute TREAT Don, make sure you've watched at least this playlist, and my "how to learn rust" video ruclips.net/video/oY0XwMOSzq4/видео.html
error: Ferris cannot be used as an identifier
let 🦀 = "";
| ^^ help: try using their name instead: `ferris`
^ this is an actual compiler error
oh that is ADORABLE
Yes, "cannot borrow `x` as mutable more than once at a time" is soooo helpful.
That sounds pretty clear to me?
Would be good to see some clippy rubbed on this exact example, as part of the video, or a follow-up.
By default, it got rid of the unnecessary `return`, but with #![warn(clippy::pedantic, clippy::nursery)], it also told us to accept &str instead.
Seems like it hasn't yet been taught to see `format!("hello {name}")` as preferable here, though.
Very correct! I was ignoring a lot of clippy errors during my testing here, in order to get the most bare-bones rust experience, for newbies.
I love clippy, and run it with those and many other options inside a `bacon` session, alongside my ide!
Definitely going to have to learn Rust at some point then. I like how useful the errors output by the interpreter in Python are for example, and this is even better. Errors in C++ from my experiences so far are… not very useful by themselves.
You'll have a really great time, here's a little playlist to get up to speed quickly, though I have plenty of videos elsewhere! ruclips.net/video/oY0XwMOSzq4/видео.html
1 crucial piece of advice:
If you end up using an Arc, delete everything and start again.
heh, certainly in application code, you'll not have to do that
I hope ALL the other programming Languages are talking notes here
This is so true! I noticed this coming from C languages to Rust.
Best errors in the business!
One of your best videos so far.
Thank you so much, I'm so pleased with it - I ditched the video I was going to produce this fortnight, and instead did this one - rewriting everything on Tuesday!!
Just found your channel and really appreciate the video's structure!
Quick errata, but on 6:58, thats not exactly what we did. We fixed the functions return type, not the type of the argument being passed to it or the argument's type itself.
Kindly,
Thank you!
Important to note that the help statements where only available after updating to rust 1.65
It's insane that even though you *just* told me to actually read the error, my immediate reaction to the first error dump was to not even read the first line properly. This will be a very hard habit to break...
Whatever language we use, I bet this is a good habit to break!
I love how some people say it's a bad thing that Rust does all that, and that "real programmers" don't need it. It's hilarious.
Rust also makes it really easy to define and enforce quality standards in your project.
In your lib file:
#![forbid(unsafe_code)]
#![warn(missing_docs)]
#![warn(clippy::unwrap_used)]
#![warn(clippy::todo)]
#![warn(clippy::panic)]
Then in your CI:
cargo fmt --check --verbose
cargo clippy -- -D warnings
You can add plenty of other lints (rust-analyzer gives you a list with explanations on what each one does when you start typing). The warn level lets developers take some shortcuts while working with the code locally, but reminds them to clean everything up before pushing. And the pipeline ensures that code doesn't get merged until it's basically flawless.
There's also cargo-deny, which searches your dependencies for known vulnerabilities and incompatible licenses. And probably many other tools I don't even know about yet.
I dig this a LOT. Have you seen no-panic, a macro that forces the compiler to prove that no execution paths could panic? crates.io/crates/no-panic
@@NoBoilerplate I saw it on one of your previous videos, but I haven't tried it yet. I imagine it gets hard to use when you have lots of dependencies, since most of them do not guarantee that there are no panics, and often you have to turn on optimizations for the panics to be optimized out.
I kind of wish there was a keyword for that in the language itself, like unsafe but the other way around ("extra_safe"? IDK), so it would get checked at compile time rather than link time, and maybe more crates would adopt it. But maybe an attribute that keeps you from using basic arithmetic operators on integers or clamp() on floats would be so annoying that no one would bother with it. Who knows...
@@yondaime500 Yeah, we have to draw the line somewhere, for me in normal code I use checked maths and never .unwrap() (enforced with clippy) and then don't worry about oom panics or other rare stuff.
2:35: "It doesn't seem like we are writing a method" I'm assuming you meant to say "a *self* method", love your channel!
functions are not called methods in Rust, unlike in Ruby. I don't think I'm wrong?
@@NoBoilerplate Ah I see what you mean. Did not realize that they actually mean a different thing. So methods are those attached to structs while functions are not? In any case, you could probably make a clarification for those that are unaware.
My understanding is that methods bound to classes/objects, whereas functions are not. Similar to attributes/member data and variables.
@@TonyUnderscore exactly, methods are functions attached to types doc.rust-lang.org/rust-by-example/fn/methods.html
I see, I never realized they actually mean different things because I heard them used interchangeably in some languages, good to know I guess.
Cargo is _literally_ the best package manager I've ever used, and probably will ever use.
Let's not get religious - we'll continue making better languages forever! But Rust is the best for now :-)
@@NoBoilerplate Definitely
rustc is the compiler :p
@@neoney fair, though I think it's reasonable to wrap up rustc, check, clippy etc into "cargo" 😂
Coming from C++, Rust compiler output is a miracle
Hell, coming from python, js, ruby etc, it's still a miracle!
I feel like a child being walked through homework. It's that easy!
The compiler really holds your hand!
Rules for living with Rusts compiler
1. The compiler hurts you because it loves you.
2. The more the compiler hurts you, the more it loves you.
3. Don't fight back, just let it happen.
"Remember, the compiler loves you" - No Boilerplate.
I am an absolute begginer into coding, I've started with Python, but than I looked into Rust and your videos are compelling me to learn Rust first. I watched your other video, I started reading the book, but it seems it is not for absolute beginners. I wish you had a course for someone like me with adhd who wants to start with code at 35 years of age.
True.
Imagine if they incorporate an alternative to GitHub copilot to the rust compiler, so that the help will use the power of machine learning similar to copilot that recommend solutions as well based on code it has trained from. Would be interesting to see using that to help you develop using rust too.
I see them as two distinct projects - the ML algorithm is probably right, but the compiler is DEFINITELY right!
@@NoBoilerplate it was just a thought. Would be interesting to maybe get two recommendations, a compiler recommendation and maybe a machine learning recommendation (based on the best code solution it could find) to help you fix an error. Not sure how easy it is to add this directly to a compiler and make it run smoothly, but it was a little idea in my head 😅
Maybe this could be researched to see it's practicality in the real world.
After a few years using it and a week or so using both, I feel like Elm's compiler is WAY better. Rust is the second best!
Fun! Could you elaborate?
@@NoBoilerplate Sure! I mean, it's a RUclips comment. But on Elm the error messages are even less cryptic. The video shows how to follow the compiler helps us find the solutions to the compilation errors. But on Elm it's spot on!
I ran into an unexpected symbol:
27| type alias Model = Int | String
^
I was not expecting to see a | here. Try deleting it? Maybe I can give a better
hint from there?
Some other:
Something is off with the body of the `init` definition:
32| ""
^^
The body is a string of type:
String
But the type annotation on `init` says it should be:
Model
LAST EXAMPLE, Check it out
This `case` does not have branches for all possibilities:
46|> case msg of
47|> Increment ->
48|> model + 1
49|>
50|> Decrement ->
51|> model - 1
Missing possibilities include:
SomethingElse
I would have to crash if I saw one of those. Add branches for them!
Hint: If you want to write the code for each branch later, use `Debug.todo` as a
placeholder. Read for more
guidance on this workflow.
You can just elm-lang.org/examples/buttons
and fiddle around making compilation fail somehow by experimenting. Its more straightforward
and that being said, both are very different, Elm is for a very narrow context: web applications. Rust is way more flexible. Having working a lot with Elm, I do think it's similar to how Rust works in some areas like error handling. Compiler messages are just friendlier and easier to read
I know nothing about programing and I'm not sure if I have the talent for that but it is tempting to give it a shot.
Once a legend said "read the error AGAIN!!"
The compiler being happy doesn’t mean there are no memory leaks. Box::leak is safe, although it makes it obvious that memory is being leaked. But, creating an Rc cycle will also leak memory and might well be accidental
True! A few people have reminded me of this. Would you say in general terms, you'd have to TRY HARD to leak memory in Rust?
@@NoBoilerplate Well it's easy if you want to leak it (which is good, it's sometimes useful). I think it really depends on the abstraction you use, if you use the Rc type to make graphs or other complex shared ownership data structures, especially intrusive ones, you may well encounter some leaks. If you don't then it is quite rare
@@NoBoilerplate I'd say in Rust, memory leaks are as unlikely to happen by accident as in most GC languages. You can do it on purpose with Box::leak. You can do it by accident with Rc-based graphs. But littering Rc liberally is already a red flag, tbh.
@@KohuGaly Righto - makes sense! Yes, Rc is useful, but spooky - I think in normal use, we'd just use references and not have a problem!
Missed opportunity: Follow up by using clippy to make this code more idiomatic. Doesn’t give too much in this particular case, but clippy certainly “teaches” some things really well, too.
(It doesn’t help you go all the way in this case; arguably, the argument type of this function should become `&str`, and there’s no compiler or `clippy` telling you, AFAICT.)
Very correct! I was ignoring a lot of clippy errors during my testing here, in order to get the most bare-bones rust experience, for newbies.
I love clippy, and run it with those and many other options inside a `bacon` session, alongside my ide!
@@NoBoilerplate Yes, `bacon` is indeed very useful.
whoa i knew the compiler was advance but i didnt know it is THIS advance. maybe i need to try to start learning it again...
It's got SO much better since I started in 2020!
I have been learning Rust for a while, but not so many companies are willing to try it for their APIs. The general notion is that it's a system language only.
that is what I hope to dispel in my Rust series - Rust is a universal language! Do check out my "turtles" video - I explain how rust is as low-level as C, and as high-level as lisp
yayyyyy
Also accurate to my experience with Rust
you not come to RUST, RUST come to you
Ah yes, rule # of our cargo cult XD
no one is safe from oxidation...
If there is a Rust's mascot, it should be Tris, not the crab :) God I love these videos.
I'm more of a cheerleader XD
holy crap, you actually run LT? I've been binging it after I found it on another one of your vids. Great podcast!
Sure do! And Modem Prometheus, though I don't voice it, I'm producer. And a new podcast in pre-production coming in the new year... STAY TUNED!
Best Rust preacher ever
Welcome to the cargo cult! XD
I've been playing around with Rust but there's always a point where I run into a compiler error and it can't help me.
For example, I needed to edit two elements of an array at the same time. Actually, not the element itself but some sub-variable of them.
I couldn't do it, bc of course I can't borrow 2 elements of an array. But I haven't found a solution and I went away for a while. Until I randomly stumbled upon it on RUclips with the name smart pointers. And well, they can become quite complex if you don't know them well. So that's where I'm stuck on currently, learning different types of smart pointers and no the compiler doesn't teach me this sadly.
That sounds tough, but you'll get there I bet!
The exciting thing is that the rust language is rich enough that it is possible to improve the errors so much that they'll eventually start suggesting smart pointers!
There are ways to mutably borrow multiple elements form the same slice. This is safe, as long as the elements are distinct.
Here's a function that borrows two elements from a slice, or gives an error if indices are equal:
fn get_mut_two(source: &mut [T], a: usize, b: usize) -> Result
{
match a.cmp(&b) {
std::cmp::Ordering::Equal => return Err(()),
std::cmp::Ordering::Less => {
let (beggining, rest) = source.split_at_mut(b);
Ok((&mut beggining[a], &mut rest[b]))
},
std::cmp::Ordering::Greater => {
let (b,a) = get_mut_two(source, b, a)?;
Ok((a,b))
},
}
}
And here's a version that borrows arbitrary N elements from a slice. Though the implementation uses unsafe, and has expensive runtime checks, that are unlikely to be optimized.
fn get_mut_n(source: &mut [T], indeces: [usize;N]) -> Result
{
// check for index out of bounds
if indeces.iter().any(|&i| i>=source.len()) {
return Err(())
}
/// check for duplicate indices
let mut sorted_indices = indeces;
sorted_indices.sort_unstable();
if sorted_indices.windows(2).any(|w| w[0]==w[1]) {
return Err(())
}
// SAFETY
// indices are all distinct and in bounds
unsafe {
Ok(indeces.map(|i| &mut *source.as_mut_ptr().add(i)))
}
}
How would you recommend to get the first remote rust job? I'm in México and most companies don't need it and I'm kind of sick of web dev
Keep an eye on Microsoft and AWS especially, they're HUGE hirers of Rust. Also, contact every one on this list www.rust-lang.org/sponsors
I love your videos every time
Thank you so much, I really enjoy making them!
@@NoBoilerplate you are the reason why I started my journey with rust and now I am doing advent of code with rust. You are literally changing lives ❤️ World is a better place because you exist ❤️
@@polares8187 Thank you so much!
i like compilers like this
Me too. Haskell's pretty great too
Hi. I've been watching your Rust videos for a while and I want to start programming in Rust now. I installed Rustup and am trying to configure my workspace right now. Rust is asking me to install MSVC build tools, but they're also offering me the option to skip ahead if I'd rather use the GNU ABI. Would you recommend using the MSVC toolchain or go the GNU pathway? I believe that software should be able to support all platforms, so I want to make sure my applications support Windows, Mac, AND Linux
Cross-compilation is trivial in Rust, so you can usually code on one platform, and make binaries for any other platform.
I'm uncertain about developing on windows, however, I've heard that it's best to use WSL2, to give a much nicer experience.
WSL is really great these days, and will side-step this, and many other issues you'll face learn.microsoft.com/en-us/windows/wsl/install
@@NoBoilerplate Tbh my computer is on the verge of running out of memory, less than 10 gigabytes left. Got no room for a Linux subsystem. But I will take your advice that cross-compilation is easy no matter the platform and use MSVC since it's the recommended toolchain for Windows. Thanks
If the compiler can produce suggestions for what might work instead of what we've written, wouldn't it be easier if we could just press a button to try out if that suggestion works without manually changing our code and another button to accept those changes if they do? Instead of manually trying it out and undoing it if it didn't work.
Maybe! The compiler doesn't have all your context though
8:10 ik the link is on screen but would be nice to have it on description/on the pinned comment so people can find it(if they got low vision/blindness/any other reason) too :)
It's very good tutorial.. but can you do something usefull in the same format from practical meanting for example implement wallet may be add GRPC for show how good / bad rust is for working in real problem scope. Best practices for example. Hello world is good.. but lay huge gap between it and something useful.. like for example spring boot application.
Do check out my other videos ruclips.net/video/Q3AhzHq8ogs/видео.html
Well this looks really impressive
You've not seen anything yet - check out my other rust videos!
This is a great idea for a video!
Thank you! Funny story, I had written an entirely different video for today, but on Tuesday I had this brainwave and wrote this video instead! I'm delighted.
I’m curious how well you could prompt chat gpt with the rust compiler. Might be a good AI automation language.
Whats your opinion on natural intuitive value on designing distributed concurrent systems when we are forced to choose between rust on one aile(or C++n java on the same aile)and functional programming languages like Haskell,scala on the other side
Don't forget Go - though I think Rust is better than Go, go is still extremely good (though it has a GC, no macros, and no super powers).
I'd say Rust has a lot of functional flavour built-in - the original compiler was writtin in ocaml, and even at one point had an functional purity system, though it was removed, as the Result passing convention works so well.
You can see the functional influence in both the iterator system, and the monads `Result` and `Option` which are foundational to the Rust standard library and ecosystem.
It's like C# at a Halloween party dressed up as Python and pretending to be nice to everyone
I've always though of it as Haskell and lisp sneaking into the cool languages party in C's overcoat
i hope to see more of "Rust Is Easy" with dealing with errors
Already gotcha covered ruclips.net/video/bu_gulee89Q/видео.html
Do check out my other videos!
@@NoBoilerplate nice thank you