Writing a CLI App in Rust! - Part 1

  Рет қаралды 79,137

Let's Get Rusty

Let's Get Rusty

Күн бұрын

Пікірлер: 54
@letsgetrusty
@letsgetrusty 3 жыл бұрын
📝 Get your *FREE Rust cheat sheet* : www.letsgetrusty.com/cheatsheet
@keatonhatch6213
@keatonhatch6213 3 жыл бұрын
This is by far the best coding tutorial I’ve ever seen. The explanation of every step, the why of every step and the refactoring steps. Keep it up I’ll be subscribing
@johnterpack3940
@johnterpack3940 Жыл бұрын
This was a perfect tutorial. Seriously, this is how you do it. I know zero Rust. But I mostly understood the original code well enough based on knowing things like Powershell and Bash. Then, even though I didn't understand much of the tweaks you made, I understood why you were making them and I have no doubt that reading the book would clarify what you did. But the real key to what makes this a phenomenal tutorial is that it is simple enough to be accessible to newcomers while still being something useful. I could easily see myself using this tool as part of a larger program I want to build. All I'd need to add is whatever it takes to decompress/decode the files I need to read and then a bit of code to manipulate those files and their contents. Libraries exist to handle the former, I just have to find them and port them to Rust. The latter is probably fairly trivial. Bottom line is that you showed me a beginner project that actually leads to something. And that is how you motivate people to learn.
@martinmecir2548
@martinmecir2548 3 жыл бұрын
You Bogdan, are a legend! Thank you very much for this, we need more tutorials like this. The refactoring steps are priceless, learned a lot Also will you make a tutorial on futures? Would love to see comparison of Rust futures with JS/TS promises!
@letsgetrusty
@letsgetrusty 3 жыл бұрын
Just put that on the todo list. Thanks for the feedback!
@thingsiplay
@thingsiplay 3 жыл бұрын
Very good tutorial. Also I appreciate how the video was edited for not wasting my time. Just the tip of the iceberg.
@mabroorahmad2182
@mabroorahmad2182 3 жыл бұрын
This is the most amazing tutorial ever. Many can write code but only few can write good code and you are morphing us into those few.
@thanhdatvo0
@thanhdatvo0 Жыл бұрын
The syntax is so elegant. Thank you for the explanation!
@delkott
@delkott Жыл бұрын
Thanks a lot for this very informative collection of tutorials, Bogdan! I am learning Rust [coming from C++] from your series; your explanations, and example collections are better than anything else I have seen online, including paid courses. If I may make a suggestion - it would be fantastic if you prepared a tutorial on developing a Rust desktop application with UI and database, say, using Tauri. Thanks again, and keep up the excellent work!
@singhsaubhik
@singhsaubhik 3 жыл бұрын
I really loved your content, appreciate that. Please always keep going with Rust. Thanks
@markmcdonnell
@markmcdonnell 3 жыл бұрын
Super useful breakdown of how to work through a problem in rust. The refactoring was of particular interest.
@exoticcoder5365
@exoticcoder5365 3 жыл бұрын
Very Useful and Easy to follow step by step
@procyonq
@procyonq 2 жыл бұрын
So nice tutorial to build a basic CLI app! Thank you so much!
@raupeniemalssatt8193
@raupeniemalssatt8193 2 жыл бұрын
@ 14:00 I would use eprintln!() instead of println! to really print an error signal insted of a normal printout.
@grvxs9230
@grvxs9230 3 жыл бұрын
Love the content.
@_jdfx
@_jdfx 2 жыл бұрын
Great tutorial, thanks Bogdan!
@jds2328
@jds2328 2 жыл бұрын
Appropriate to your patience *SO MUCH*
@GolangDojo
@GolangDojo 3 жыл бұрын
I wouldn’t mind wine and banters at this new place
@nathanielwoodbury2692
@nathanielwoodbury2692 3 жыл бұрын
Wow Thankyou so much for this
@alvaroandresherradacoronel8972
@alvaroandresherradacoronel8972 8 ай бұрын
Hi Bogdan, At the beginning of the refactoring section you have this line of code formatted like this: let contents = fs::read_to_string(filename) .expect("Something went wrong reading the file"); I'm following the video on VSCode using the extensions you recommend on your channel, and it forces the format to this: let contents = fs::read_to_string(filename).expect("Something went wrong reading the file"); I wanted to know what your settings are on RustAnalyzer and VScode or if you know how to change that setting. I appreciate your help (or the help of anyone who happens to read the comment).
@RodrigoStuchi
@RodrigoStuchi 2 жыл бұрын
Absolutely amazing content you sir are producing. I'm your channel. Thank you
@sathishkannan6600
@sathishkannan6600 10 ай бұрын
I think you can return Result type from the main and it will automatically exit if an error occurs, but you need specifiy the error.
@tashima42
@tashima42 3 жыл бұрын
This is the type of video that te community needs
@inx1819
@inx1819 3 жыл бұрын
When will there be a video on the Box? Sounds useful but I can't wrap my head around it hah
@inx1819
@inx1819 3 жыл бұрын
If I understand correctly, dyn Error is simply any type that implements the Error trait. However, it could be any type - a struct with 1 field or 100, the compiler doesn't know the size, so it can't be returned from a function like that. To fix that, we put it on the heap inside of a Box, basically a pointer, along with the info on the size of the data inside. The compiler knows the size of Box because it's essentially just a pointer.
@letsgetrusty
@letsgetrusty 3 жыл бұрын
Sounds like you figured it out. Your explanation makes sense to me although I haven't dug into it yet.
@radiknazmiev
@radiknazmiev 3 жыл бұрын
@@inx1819 Why not just Box? What is the dyn keyword for?
@jacobhinchliffe6659
@jacobhinchliffe6659 3 жыл бұрын
@@radiknazmiev dyn means we get the type at run time I believe?
@CYBERNETIC-ANGEL
@CYBERNETIC-ANGEL 8 ай бұрын
what does the "{:?}" mean in the first println! argument?
@sahilverma4077
@sahilverma4077 3 жыл бұрын
the new setup looks better
@pynchia4119
@pynchia4119 2 жыл бұрын
@3.07 why do you use a reference to each arg in the newly created collection? Why not assign it as a String? Also: the arg strings are stored somewhere already, why do we need a collection if we use references later? Can't we just refer to the original strings, e.g. let query = args.next().expect("error");
@ak_clirustacean6241
@ak_clirustacean6241 2 жыл бұрын
Thanks for saving our time! I have a little question, when we created parse_config function we are expecting reference to an array of strings as an argument, but what we're passing is vector of strings. I see it works but could you please elaborate it a little bit more? What's the rule behind it that makes a compiler nice to us all of a sudden :) ?
@nofacee94
@nofacee94 2 жыл бұрын
That is not an array of strings as an argument, it is a reference to a slice of the vector.
@mikutut
@mikutut 2 жыл бұрын
What do we pass as an argument is not an array of strings, but in fact a slice of the vector. We didn't specify an index or a range, which means we are passing a slice of the whole vector.
@asdqwe4427
@asdqwe4427 2 жыл бұрын
Hmm, having a new function return a result feels like a bit of a smell to me. Is this a common way to handle things in rust? To me a constructor should always work, and for that reason I would much prefer to check all the errors before calling it. If I'm getting the arguments for a constructor from a vector or an arrray, I would probably do the validation beforehand and in this simple case I probably wouldnt create a constructor at all for this struct. But perhaps I am wrong and there is a good reason to do this?
@knowledgedose1956
@knowledgedose1956 Жыл бұрын
Hi, Bogdan. Can you advise any Vscode plug-ins for rust. I love how you get types autocompleted in your setup
@xDanishGamerz
@xDanishGamerz 3 жыл бұрын
at 10:22 you use config.filename twice in your parameters. When i try to do that it says I can't because I move values, so fix it used & to reference it in the paramters. Why is it you didnt need to do reference the values but I do?
@lee45283
@lee45283 3 жыл бұрын
What rust language analyser are you using in VS code?
@inx1819
@inx1819 3 жыл бұрын
there are two main extensions: the "official" one and "rust-analyser". The second one has more features and gets updated more.
@ati43888
@ati43888 Жыл бұрын
Thanks
@umut8244
@umut8244 2 жыл бұрын
The original rust Lang Book is not so good in this chapter. But you are good.
@ClearerThanMud
@ClearerThanMud 3 жыл бұрын
Good work as usual. Just a note for viewers: in truth you wouldn't want to use read_to_string() for an arbitrary file -- it's better to iterate over strings read one by one from the file. read_to_string() is great for config files and the like that you know are going to be small and you need the whole thing at once. I'd like to see Bogdan (sp?) do another CLI video in which he uses structopt and handles errors via the anyhow crate (or something similar), with main() returning a Result. Rust has good support for CLIs, so we really should use it. Bonus points if you show viewers how to process multiple files simultaneously.
@jacobhinchliffe6659
@jacobhinchliffe6659 3 жыл бұрын
He is just following along with the Book, but I'd like to see to see somebody making a video on that
@DuyTran-ss4lu
@DuyTran-ss4lu 2 жыл бұрын
Awesome
@dzibanart8521
@dzibanart8521 3 жыл бұрын
Question, Couldn't have you used '?' operator Instead of .unwrap_or_else() ? If not, why?
@inx1819
@inx1819 3 жыл бұрын
Where? Inside the main function when checking the result of the Config::new function? You can but it doesn't make sense here because it defeats the point - we wanna handle it ourselves, to print a nice error message. Also you'd need to change the main function to return a Result - and frankly I hate doing that on the main().
@FrayedString
@FrayedString 2 жыл бұрын
FWIW following this video on Jan 18, 2022, I had to change the process::exit(1); to process::exit(0); to avoid an additional error message saying the process didn't exit successfully. Running on Windows. stable-x86_64-pc-windows-msvc unchanged - rustc 1.58.0 (02072b482 2022-01-11)
@miguelguerrero3394
@miguelguerrero3394 2 жыл бұрын
Same problem, thank you
@PatrickIsbendjian
@PatrickIsbendjian 2 жыл бұрын
Basically, if you exit because of an error you shouldn't use exit(0) which means your program executed successfully. It doesn't matter much in this particular case, but if you were to chain your program with others inside a shell script or on a command line, it would cause the script or chain to miss the failure, which may be problematic.
@do0nv
@do0nv 2 жыл бұрын
That's cargo outputting the error. The .exe file doesnt show the "process didn't exit successfully" message.
@caveofmovies8597
@caveofmovies8597 3 жыл бұрын
👍
@pynchia4119
@pynchia4119 2 жыл бұрын
@2.01 you say ".collect needs to know what type of collection we want". WHAT? How does it get the type you specify to the variable you are creating? I understand the Vec type handles generics, and that's what you specify the args variable should hold. But what has it got to do with .collect? I think your statement is very misleading
@arttartkhai
@arttartkhai Жыл бұрын
I'm nobody! Who are you? Are you nobody, too? Then there's a pair of us - don't tell! They'd banish us, you know. How dreary to be somebody! How public, like a frog To tell your name the livelong dreary To an admiring bog!
Writing a CLI App in Rust! - Part 2
16:41
Let's Get Rusty
Рет қаралды 35 М.
Closures in Rust
19:53
Let's Get Rusty
Рет қаралды 79 М.
1, 2, 3, 4, 5, 6, 7, 8, 9 🙈⚽️
00:46
Celine Dept
Рет қаралды 70 МЛН
Elza love to eat chiken🍗⚡ #dog #pets
00:17
ElzaDog
Рет қаралды 22 МЛН
Triple kill😹
00:18
GG Animation
Рет қаралды 18 МЛН
Amazing remote control#devil  #lilith #funny #shorts
00:30
Devil Lilith
Рет қаралды 12 МЛН
Why do developers hate Rust?
8:20
Let's Get Rusty
Рет қаралды 138 М.
Google’s adoption of Rust has finally paid off…
4:39
Let's Get Rusty
Рет қаралды 102 М.
Parse Rust CLI Args With Clap 🦀 Rust Tutorial
54:03
Trevor Sullivan
Рет қаралды 12 М.
Why Rust is NOT a Passing Fad...
8:54
Travis Media
Рет қаралды 42 М.
My favorite Rust design pattern
7:00
Let's Get Rusty
Рет қаралды 40 М.
All Rust features explained
21:30
Let's Get Rusty
Рет қаралды 319 М.
Where is Rust being used?
11:46
Let's Get Rusty
Рет қаралды 115 М.
Rust for the impatient
10:43
No Boilerplate
Рет қаралды 731 М.
Concurrency in Rust - Creating Threads
10:41
Let's Get Rusty
Рет қаралды 56 М.
Low Battery 🪫🥹🥹🥹
0:10
dednahype
Рет қаралды 4,2 МЛН
Handy remote!
0:25
LeraKek
Рет қаралды 3,5 МЛН