Common Collections in Rust

Поділитися
Вставка
  • Опубліковано 28 лис 2024

КОМЕНТАРІ • 108

  • @letsgetrusty
    @letsgetrusty  3 роки тому +13

    📝 Get your *FREE Rust cheat sheet* : www.letsgetrusty.com/cheatsheet

  • @daque1960
    @daque1960 3 роки тому +37

    I am finally using vectors and hashsets. I didn't have to store a key/value and the fact it doesn't allow duplicate entries was perfect. I still make tons of mistakes but these videos help a lot. If you're learning making a lot of mistakes and fixing them is a good way to learn.

  • @gautamprikshit1
    @gautamprikshit1 3 роки тому +72

    नमस्ते brother you're the best. Thanks for saving me from go🌚🤝🏼

    • @Christobanistan
      @Christobanistan 7 місяців тому

      From what others told me, Go is really only good for back end services, not games or GUIs. Is that right?

    • @afraid2letgo
      @afraid2letgo 4 місяці тому

      ​@@Christobanistan Mostly go is used for backend etc, yes

    • @Christobanistan
      @Christobanistan 4 місяці тому

      @@afraid2letgo Doesn't answer my question.

    • @afraid2letgo
      @afraid2letgo 4 місяці тому +1

      @@Christobanistan Go is mostly used for backend -> Go is good for backend. Go is mostly used for backend -> Go is barely used for GUIs/games, if ever -> Go isn't really good for GUIs/games. What part of your question did I miss?

    • @Christobanistan
      @Christobanistan 4 місяці тому

      @@afraid2letgo Sorry, I thought I had explicitly asked. What exactly is it about Go that makes it unsuitable for GUIs? I understand the nondeterminism of the GC is why games aren't a good idea, but no one seems to know why it's unsuitable for GUIs.

  • @2002budokan
    @2002budokan 2 роки тому +16

    Rusty content suggestion:
    How about a playlist that involve each type in Rust collections library, that tells their traits, implementations etc? Or series of playlists that covers the whole Rust standart library? Rust is a big ocean that can feed Rusty channels. There are very interesting crates too, for example wgpu...

  • @yapayzeka
    @yapayzeka 2 роки тому +19

    at 10:10 I made matchmaking with inspiration from previous lessons:
    match row.get(0) {
    Some(data) => match data {
    SpreadsheetCell::Int(i) => println!("{} is an integer type data.", i),
    _ => println!("Cell has not an integer type data."),
    },
    None => println!("Cell not exists!"),
    }

    • @alex283d
      @alex283d 2 роки тому +12

      Could even use a nested destructuring instead of nesting match expressions:
      match row.get(0) {
      Some(SpreadsheetCell::Int(i)) => println!("{} is an integer type datum.", i),
      Some(_) => println!("Cell has a non-integer type datum"),
      None => println!("Cell does not exist."),
      }

  • @firstname1817
    @firstname1817 2 роки тому +3

    Thanks for the explanation at 13:56. While reading this chapter I was trying to wrap my mind around why it's written like that

  • @sunnymittal1906
    @sunnymittal1906 2 роки тому +6

    In case anyone's interested, in newer versions of Rust (and perhaps even the one Bogdan is using), you don't actually need to specify a type when initializing an empty vector, even though "rust doesn't know what the type will be." It's probably good practice but the compiler will infer the type after the first usage:
    ```
    let mut v = Vec::new();
    v.push(1);
    ```
    This compiles just fine because the first time rust sees something going into `v`, it sets the type accordingly, in this case to i32.

    • @Calebanton
      @Calebanton Рік тому

      He said something along the lines of like "Because we're not adding anything of a particular type, we have to specify the type" so I don't think the video is outdated or anything

  • @nikolaevkirill
    @nikolaevkirill Рік тому +1

    Thanks for the video. For a newbie like me, this is a pretty confusing example (7:55). After playing around with the code I was able to understand the proper solution. We're not able to assign variable `third` a reference to the third value, but it's totally working to assign it the value. So if you need to mutate the vector but before the mutation you want to store the `third`, just do it by value. That totally makes sense.

  • @scheimong
    @scheimong 3 роки тому +9

    Should probably mention collect. It's one of Rust's best ergonomic features.

  • @hchydra3666
    @hchydra3666 3 роки тому +2

    lool you and wallace gotta be having fun. glad you chose the right side

  • @sephirothu1290
    @sephirothu1290 Рік тому +1

    Hello
    These series are the best rust tutorial I have ever found on youtube
    Thank you so much

  • @gauravbhat3291
    @gauravbhat3291 7 місяців тому +1

    i am using this series as revision or summery and that is best for me after reading the book for any chapter or before reading i am learing kind of many new things from this

  • @lawalbabatundeutility4230
    @lawalbabatundeutility4230 Рік тому +2

    Thanks for this amazing content Bodgan! I am almost done with the rust book and I can testify that this series helps cement the little I have known so far. I hava question please: how did you set up rust-analyzer to do type annotation automatically?

  • @PhilippeCarphin
    @PhilippeCarphin 2 роки тому +1

    I wouldn't normally watch a tutorial like this for another language. I would actually go through the rust book that you are presenting.
    The problem with that is I can't help myself from scrolling right through to the first code example, and if I think I can understand it, I paste it in my own code or adapt it to what I want to do. I know enough different languages that this usually works well.
    But with the whole ownership stuff and the result types, and the "if let Ok(new_variable) = some_func()", I wasn't able to understand it just from looking at the syntax. Well ... I did sorta figure out what the "if let Ok(new_var) = some_func()" was doing, but seeing as I had skipped learning about Enums (which are quite different from what I expected), I can't say that I understood it for real.
    Until I watched you videos which forced me to go through everything slowly.

    • @jeffreyefemena1082
      @jeffreyefemena1082 8 місяців тому

      true, rust book is the only programming language I've learnt reading books and watching videos, and it's so exciting

  • @marcoantonio7648
    @marcoantonio7648 Рік тому +1

    the section on string just saved me from hours of frustrations (after I already have hours of frustrations lol)

  • @pythona291
    @pythona291 Рік тому

    great work cool work, for those who are uncomfortable reading books or just don't like reading books.

  • @idcmardelplata
    @idcmardelplata Рік тому +1

    men, you explanations are really really good, thanks for that. 🥰

  • @jamesbarrow
    @jamesbarrow Рік тому

    I've been wanting to create a programming from scratch video series, and touch on encodings, how assembly gets run by a bare metal computer with the CPU, registers etc. and how that is the stack and heap and how it works. I've also wanted to learn Rust. This isn't the first video of your series I've watched but man, I love how you explain things. It's paced so nicely, really a pleasure. You are getting my motivation back to start on that series of videos

  • @pygeekrfoo820
    @pygeekrfoo820 Рік тому

    I feel like I ran a marathon after watching each of these videos

  • @sureshnimbalkar1929
    @sureshnimbalkar1929 5 місяців тому

    At video location 10.17, Bogdan says in a match statement, an underscore (_) covers all other options in an enum. In my view, this is only partially correct. In the underscore option, we are ignoring the values from the enum. If we use 'other' instead (of underscore), we can use the respective values.

  • @jspiro
    @jspiro 3 роки тому +4

    At 7:50 I was hoping you'd explain how we could solve the problem of wanting to print out the third element value after pushing onto it. Maybe it's obvious, but you built up the problem without the solution :-)

    • @tsg1zzn
      @tsg1zzn 3 роки тому +3

      You either need to copy the value in the first place, or you need to swap line 4 and 5. This is also what you need to do in C++ to avoid risking a segfault. The difference is that rust gives a compilation error, C++ compiles and hopes for the best.

    • @tsg1zzn
      @tsg1zzn 3 роки тому

      To copy a simple integer, you just remove the &. I assume we will learn about copying more complex types later.

  • @a_maxed_out_handle_of_30_chars

    this was amazing, thank you :)

  • @luo2395
    @luo2395 2 роки тому +1

    Thanks for those amazing videos talking about rust!

  • @Tvaroh
    @Tvaroh Рік тому

    Thanks! What Linux distribution are you using? Fonts look very MacOS-esque.

  • @luizneri
    @luizneri 2 роки тому +4

    Hello, How would you represent a double linked list in Rust? I've heard that graphs are difficult to represent in rust due ownership

    • @letsgetrusty
      @letsgetrusty  2 роки тому +8

      Yes linked lists and graphs are difficult in Rust and not something you should dig into when first learning the language. There is a book dedicated to implementing linked lists: rust-unofficial.github.io/too-many-lists/

  • @adamhenriksson6007
    @adamhenriksson6007 3 роки тому +15

    "In order to keep the rust standard library lean, the ability to iterate over grapheme clusters is not included by default. "
    ... they did what now?

    • @fenilli
      @fenilli 3 роки тому +6

      it does make sense if you think about the amount of libs/projects that do not need to do this.

    • @SemiMono
      @SemiMono 2 роки тому +2

      ​@@fenilli Agreed. Unicode is a massive subject. I'm all for putting such things in a library. Especially in a lower-level language like rust.

  • @WilmanArambillete
    @WilmanArambillete 2 роки тому

    this channel is awesome! Incredible level ! congrats

  • @netify6582
    @netify6582 2 роки тому

    When you print the last map, I'm wondering why it prints items is random order? I would expect first word will be always first there but it's not the case. Is there some hidden parallelism inside or what?

  • @prasanthkarunakaran5883
    @prasanthkarunakaran5883 6 місяців тому

    I think at 7:26 in the video, say will throw error.
    fn main() {
    let mut v = vec![1, 2, 3, 4, 5, 6,];
    let third = &v[3];
    v.push(7);
    match v.get(2) {
    Some(third) => println!("The third elemet is {}in vector {:?}", third, v),
    None => println!("there is no thrid element.")
    }
    }
    But I tried it in rust 1.78. The code working fine. Is they updated it?

  • @RAJASABC
    @RAJASABC Рік тому

    Do you have the code from these example in Github?
    it will be easier to clone the repo and run them to follow the videos, than typing them,,

  • @alexisbatyk6301
    @alexisbatyk6301 2 роки тому

    Great content! What extensions do you use?

  • @adrian_sp6def
    @adrian_sp6def Рік тому

    I am confused. What is a reference in Rust? It is more like a pointer or like a reference? looks like I can access object's fields like a reference but to assign a value to referenced field I need to dereference it like a pointer.

  • @shavais33
    @shavais33 8 місяців тому

    Trying to understand HashMap::entry. That function returns an owned Entry

  • @rtdietrich
    @rtdietrich 11 місяців тому

    Complex? I had to laugh at the end at how easy it was. I thought oh dear what's coming....and then some baby stuff

  • @samdavepollard
    @samdavepollard 2 роки тому

    the video on strings, mentioned about 18 mins into this one: ua-cam.com/video/Mcuqzx3rBWc/v-deo.html

  • @vmachacek
    @vmachacek 2 роки тому +2

    hey Bogdan, thank you for your videos, it's great Rust resource. Considering you are from Ukraine (My guess, you mentioned it before?) fingers crossed everything will be fine in next coming weeks & months

  • @jackho4449
    @jackho4449 3 місяці тому

    Similarly at 07:55, I type the code as follows:
    fn main() {
    let mut v = vec![1, 2, 3, 4, 5];
    let first= &v[0];
    v.push(6);
    }
    But I didn't get any error, instead just a warning:
    warning: unused variable: `first`
    --> src/main.rs:3:9
    |
    3 | let first = &v[0];
    | ^^^^^ help: if this is intentional, prefix it with an underscore: `_first`
    |
    = note: `#[warn(unused_variables)]` on by default
    Can anyone explain why the borrowing rule does not work here? Thanks!

  • @HrishikeshMuruk
    @HrishikeshMuruk 3 роки тому +2

    Could you do a video about setting up VS code to get prompts and shadow fills like you do. For example, when I type let s1 = String::from("Hello"); I do not get the ":String" in light font like you do. Also, you mentioned in one of your videos that you are running a "language" server. How does that help? Could show how to install that feature?

    • @letsgetrusty
      @letsgetrusty  3 роки тому +7

      The "language server" is what gives me those type annotations (shadow text). Simply install the *rust-analyzer* VS code plugin.

  • @foobar1269
    @foobar1269 2 роки тому

    I would like to see how I can use rust to pull a CSV file from SFTP (SCP) then parse it and iterate through it.

  • @chrs-wltrs
    @chrs-wltrs 2 роки тому

    What are the use cases where you would want to access the bytes or characters of a UTF-8 string as opposed to the graphemes?

  • @yesudeep
    @yesudeep 16 годин тому

    🙏 नमस्ते 🙏 Love your videos! ❤

  • @elhusseinali8934
    @elhusseinali8934 3 роки тому

    thank you for your efforts

  • @TeppopucT
    @TeppopucT Рік тому

    А я то думаю почему мне так легко понимать ваши уроки))
    Спасибо

  • @sahilverma4077
    @sahilverma4077 3 роки тому +2

    damn I started laughing when you said नमस्ते (namaste)

    • @letsgetrusty
      @letsgetrusty  3 роки тому +6

      Did I butcher it? 😅 At least my Russian pronunciation is on point 😎

    • @sahilverma4077
      @sahilverma4077 3 роки тому +2

      @@letsgetrusty it's fine it's not your mother tongue so can't help

    • @HrishikeshMuruk
      @HrishikeshMuruk 3 роки тому +1

      @@letsgetrusty Kudos for explaining UTC encoding and unicode. Especially Grapheme clusters. दन्यवादः (Thank you)

    • @31redorange08
      @31redorange08 3 роки тому +1

      @@HrishikeshMuruk It's UTF.

  • @henrmota
    @henrmota Рік тому

    Its missing a video covering streams, to hande large amounts of data on demand.

  • @joemamium
    @joemamium 2 роки тому +1

    Your videos are extremely helpful. I wish you had the channel membership option turned on or, maybe, a Patreon page.

    • @letsgetrusty
      @letsgetrusty  2 роки тому +10

      I do this out of the kindness of my heart :)

    • @yutongchen5006
      @yutongchen5006 2 роки тому

      @@letsgetrusty Wow, don't know what to say now. Just want to send you tons of appreciation and love ❤️ Honestly if C++ has tutorials like yours, it would save me, a beginner, huge amount of time!! 😭

  • @TibinThomas1993
    @TibinThomas1993 3 роки тому +2

    line number 4 at 9:00, throws error

  • @mikesbasement6954
    @mikesbasement6954 2 роки тому

    I must be missing something. From what you said it sounds like once you add something to a vector you can't use it anymore because it's out of scope. If that's the case, what use is a vector?

    • @minatonamikaze2637
      @minatonamikaze2637 Рік тому

      not really, he mentioned vectors are stored on heap so they get dropped when they get out of scope

  • @tak68tak
    @tak68tak 3 роки тому

    Amazing video

  • @Keolamation
    @Keolamation 6 місяців тому

    I want a guide on making a Solana smart contract. lol

  • @teachforyou6489
    @teachforyou6489 2 роки тому

    Well Explained

  • @MattTheCuber1
    @MattTheCuber1 2 роки тому

    What extension are you using that shows the types when not explicitly stated?

    • @MattTheCuber1
      @MattTheCuber1 2 роки тому

      Found it! (it's at the bottom of the application: rust-analyzer)

  • @bananatop6059
    @bananatop6059 Місяць тому

    Very clear video, shame about the background music. Very distracting.

  • @yassin_eldeeb
    @yassin_eldeeb 3 роки тому

    you're the best

  • @vantutrieu97
    @vantutrieu97 2 роки тому +1

    omg, this topic very very difficult for me

  • @miniminerx
    @miniminerx 2 роки тому

    Guys rust kinda difficult. Just keep swimming. I really decided to jump from python to rust, so be worth it though!

    • @simoachangli
      @simoachangli 2 роки тому

      Every time I encounter some difficult concepts I say is this language really worth

  • @babuOOabc
    @babuOOabc 2 роки тому

    8:00

  • @cysys
    @cysys 2 роки тому

    Why use vectors ? array looks easier to use for same use cases !?

    • @nofacee94
      @nofacee94 2 роки тому +1

      arrays unlike vectors are of a fixed size

    • @cysys
      @cysys 2 роки тому

      @@nofacee94 thanks ! I was don't understand we can't push new data in array in Rust :/

    • @Gramini
      @Gramini 2 роки тому

      @@nofacee94 Not only are arrays of a fixed size, but that size must also be known at compile time.

  • @marktime.
    @marktime. Рік тому

    your flag is facing the wrong way

  • @GolangDojo
    @GolangDojo 3 роки тому +4

    Real programmers need no generics

    • @letsgetrusty
      @letsgetrusty  3 роки тому +15

      Go doesn't have generics? Sounds like an unfinished language.

    • @hchydra3666
      @hchydra3666 3 роки тому +15

      Real world projects need no garbage collection spikes

    • @GolangCafe
      @GolangCafe 3 роки тому +1

      @@letsgetrusty it will soon! (Go2) :)

    • @sleepymarauder4178
      @sleepymarauder4178 3 роки тому +6

      @@GolangCafe Go2Rust?

    • @OggerFN
      @OggerFN 3 роки тому +2

      @@GolangCafe
      more like Go use a decent language

  • @lucifercoxi8324
    @lucifercoxi8324 3 роки тому +4

    300th view

  • @dmytrobortnichuk8501
    @dmytrobortnichuk8501 2 роки тому

    Із кожним новим відео розумію наскільки Голанг сакс

  • @webmakaka
    @webmakaka 3 роки тому

    Здравствуйте!

  • @ЛёняМазин
    @ЛёняМазин 2 роки тому +1

    Здраствуйте!

  • @v0xl
    @v0xl 2 роки тому

    Use hashbrown, it's faster then HashMap

    • @Gramini
      @Gramini 2 роки тому

      Good call. But you no longer need it today, as it's now the standard.
      "Since Rust 1.36, this is now the HashMap implementation for the Rust standard library."
      (from their GitHub)

    • @v0xl
      @v0xl 2 роки тому

      @@Gramini yeah for fast non-secure hash maps there's AHashMap from ahash, faster then default impl

  • @gammyhorse
    @gammyhorse Рік тому

    The compiler panics here:
    let mut v4 = vec![1, 2, 3, 4, 5];
    let third = &v4[2];
    v4.push(55);
    println!("The third element is: {}", third);
    But it's everything ok here:
    let mut v4 = vec![1, 2, 3, 4, 5];
    let third = &v4[2];
    println!("The third element is: {}", third);
    v4.push(55);
    And the question is WHY? I' m not changing the fucking third element no matter what nor the base address of the fucking vector that the third variable was binded to. The is no point for this stupid restriction.

  • @ranaahsanansar524
    @ranaahsanansar524 2 місяці тому

    Awesome Content

  • @hcoderhy768
    @hcoderhy768 9 місяців тому +1

    Здравствуйте!