Learning Rust
Learning Rust
  • 155
  • 53 878
Closures inside functions | Rust Language
Using a closure inside a function in Rust. I show an example with 3 different closures, each can be passed to the very same function.
"The Fn traits are important when defining or using functions or types that make use of closures."
📗 doc.rust-lang.org/book/ch13-01-closures.html
- chapters -
00:00 intro - closures inside functions
03:00 adding another closure
09:00 looking at the function definition
19:53 talk about vim/neovim
My vim config is here :
📗 gist.github.com/RGGH/3ba6b194bef3b75186ac3cfb45890ee9
* This video is me 'learning' so please take from it what you can, including my code, but take it for what it is - a video showing a concept and one example through my eyes! As always, the Rust docs are your friend and hopefully this has given you inspiration to learn more.
** The goal of these videos is to capture and share the learning process and think about how best to learn what can at times be a challenging language to learn. 🤔
*** The first half of the video is a demonstration of this, the 2nd half is more like a live stream (except it's not!)...just me talking about learning from books, neovim, a quick look at "Far" which I need to either learn properly or go back to :%s/foo/bar/g
🧐 Here's some word salad from chatGPT :
"Using multiple closures within a single function in Rust enhances code modularity, reusability, and readability. It allows capturing different parts of the environment, simplifies complex logic, and leverages functional programming paradigms for concise, expressive code."
In a future video we'll look at a function that returns a trait and a function that returns a closure.
Try out the code from the video here in Rust Playground:
📗 play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=e6132b69eeed1ab15cc36fa63c82255c
#rustprogramming #learningrust #rustlang
มุมมอง: 144

วีดีโอ

DOCX creator built with Rust docx-rs 🦀 | Rust Language
มุมมอง 2389 ชั่วโมงที่ผ่านมา
Docx-rs based Docx file writer application written in Rust. This code allows you to create your own Word docs (docx files) and supply your own text file to provide the content. I've used Clap to accept arguments as well, which allows you to get the relevant data into the specific parts the document. This has not been tested on Windows, (I use Linux) but this should work on Windows too. Please t...
SurrealDB Docs + Lifetimes / Not Live Stream | Rust Language
มุมมอง 18516 ชั่วโมงที่ผ่านมา
A look the SurrealDB docs and the Rust code - lifetimes - and why they used them - much of what I have seen in books for beginners usually sticks to String as the type in a typical struct and I wanted to experiment and freestyle it a bit. surrealdb.com/docs/surrealdb/embedding/rust If I was more experienced with Rust this would have been a "Live Stream" - alas it was recorded as a "NOT live str...
Generics + Where Clause | Rust Language
มุมมอง 117วันที่ผ่านมา
This video shows how to use the 'where' clause - when specifying generic types I take an example from "MOL" - Rust in a Month of Lunches by David Macleod and change it to return a value from the function and then rewrite the function the 'other way' and test it 00:00 intro 01:41 code 11:40 different ways "When using a where clause is more expressive than using normal syntax" doc.rust-lang.org/r...
for_each v map | Rust Language
มุมมอง 69วันที่ผ่านมา
A quick comparison between for_each and map in Rust Language. 🟩 Try Rust Playground play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=4f161dd2cc4a671fc1d3e6ce5e244956 🟩 read more about for_each in the official Rust docs here : doc.rust-lang.org/std/iter/trait.Iterator.html#method.for_each Linux Hosting - VPS server - Webdock 🟩 Webdock Linux Hosting : webdock.io/en?maff=wdaff 170 N...
Unit Type | Rust Language
มุมมอง 183วันที่ผ่านมา
What is Unit type? How is different from None? This video looks at the differences. We also look at an example from "Rust in a month of lunches" and see how unit type works with a match arm Linux Hosting - VPS server - Webdock 🟩 Webdock Linux Hosting : webdock.io/en?maff=wdaff 170 Nostr @RngWeb findthatbit@iris.to findthatbit.info/ redandgreen.co.uk/ #Rust #unit #rustlang
iced project in Rust - 'guissh' | Rust Language
มุมมอง 52114 วันที่ผ่านมา
How to build an iced project in Rust - this uses SSH and connects to a remote host, issues a command and displays the stdout back to the GUI. iced playlist: th-cam.com/play/PL38rDfx7QwKZQWjTCmYQ7IZTuXqR3bd3p.html 00:00 intro 02:37 libssh 03:21 explanation of code 09:47 demonstration Full project code for "guissh" on GitHub: 🔗 github.com/RGGH/guissh Even if you are not so interested in building ...
iced GUI | Rust Language
มุมมอง 2.4K21 วันที่ผ่านมา
Iced is a cross-platform GUI library for Rust. To get started I followed to todo list example, and then decided to build a GUI to connect to a remote server via SSH and run some commands. 00:00 intro 02:15 demo 04:59 code 13:47 github iced playlist: th-cam.com/play/PL38rDfx7QwKZQWjTCmYQ7IZTuXqR3bd3p.html 🔗 github.com/RGGH/guissh Even if you are not interested in building apps with a GUI it's st...
Logging with Log | Rust Language
มุมมอง 23528 วันที่ผ่านมา
How to set up logging in Rust with the Log crate, using their example plus some additional code, and a banner! Linux Hosting - VPS server - Webdock 🟩 Webdock Linux Hosting : webdock.io/en?maff=wdaff 170 Nostr @RngWeb findthatbit@iris.to findthatbit.info/ redandgreen.co.uk/ #Rust #logging #rustlang
Destructuring | Rust Language
มุมมอง 121หลายเดือนก่อน
This video gives an overview of : 🟢 Conditional Destructuring 🟢 Destructuring Tuples 🟢 Destructuring Arrays 🟢 Destructuring Structs 🟢 Partial Destructuring 🟢 Ignoring Fields with _ 🟢 Destructuring References Linux Hosting - VPS server - Webdock 🟩 Webdock Linux Hosting : webdock.io/en?maff=wdaff 170 Nostr @RngWeb findthatbit@iris.to findthatbit.info/ redandgreen.co.uk/ #rustlang #destructuring #...
Learning about "take" with a Linked List example | Rust Language
มุมมอง 152หลายเดือนก่อน
I share Some of the things I learned from studying how to do a Linked List in Rust, especially using the "take()" method. The idea was to learn how to manipulate the structs and struct data contained within the Nodes of the Linked List. In summary, this was to practice using Box, Option, and Generic type T as much as possible. Note I think of "next" as "previous" mainly due to learning about th...
Learning a new approach to Recursion | Rust Language
มุมมอง 298หลายเดือนก่อน
Taking a new approach to learning recursion. I studied a few tutorials and videos but found that this technique from the book "Think like a programmer" helped a lot. By making an iterative solution first and the altering it to recursion using the "last part" / "last element" is quite a useful way to approach the problem. I tried the general idea in Python first and debugged it in VScode debugge...
Live Queries SurrealDB | Rust Language
มุมมอง 188หลายเดือนก่อน
In this video I show examples of live queries in Rust using the SurrealDB database and Rust SDK. The live query stream updates the display as a table, record, or range of records are updated, in real time! In the second half of the video I deserialize the Result with a custom print function. 🦀 SurrealDB Rust Playlist th-cam.com/play/PL38rDfx7QwKaluI7PoOrjlmjGTgx45C2Y.html Relate in SurrealDB: s...
SurrealDB & Rust | Rust Language
มุมมอง 287หลายเดือนก่อน
Using Surreal inside Rust - Learning more about using $var and Let with type::table and type::thing within a SurrealQL create and relate statement inside a Rust function. We also look at how to pass a variable from a Rust function into a binding and use it in the Surreal Query. Main repo of my code on GitHub: 🟩 github.com/RGGH/surrealtest 🦀 SurrealDB Rust Playlist th-cam.com/play/PL38rDfx7QwKal...
Embedded Database built with SurrealDB | progress #2 | Rust Language
มุมมอง 271หลายเดือนก่อน
Project progress update 2 - Learning SurrealDB and embedding it into a single binary executable compiled from Rust code - using the SurrealDB SDK and building a command line database for "products" which in this case is a collection of magazines to one day list on Ebay. This is built with SurrealDB version 1.3.1 as of Mid March 2024. Since the previous video I have refactored main.rs and put th...
Embedded Database | work in progress | Rust Language
มุมมอง 2562 หลายเดือนก่อน
Embedded Database | work in progress | Rust Language
SurrealDB and Rust | UPDATE & RELATE | Rust Language
มุมมอง 1K2 หลายเดือนก่อน
SurrealDB and Rust | UPDATE & RELATE | Rust Language
Sorted By | Rust Language
มุมมอง 1022 หลายเดือนก่อน
Sorted By | Rust Language
Learning SurrealDB for Rust | Code Example | Rust Language
มุมมอง 6752 หลายเดือนก่อน
Learning SurrealDB for Rust | Code Example | Rust Language
SurrealDB - getting started | Rust Language
มุมมอง 1.3K2 หลายเดือนก่อน
SurrealDB - getting started | Rust Language
write! v format! | Rust Language
มุมมอง 4902 หลายเดือนก่อน
write! v format! | Rust Language
Proof of Work SHA256 | Rust Language
มุมมอง 6312 หลายเดือนก่อน
Proof of Work SHA256 | Rust Language
Filter & Fold | Rust Language
มุมมอง 7322 หลายเดือนก่อน
Filter & Fold | Rust Language
Reverse Byte Order | Rust Language
มุมมอง 1982 หลายเดือนก่อน
Reverse Byte Order | Rust Language
State Pattern in Rust | Rust Language
มุมมอง 1.5K2 หลายเดือนก่อน
State Pattern in Rust | Rust Language
Use Arc and Mutex to update shared data with threads | Rust Language
มุมมอง 1902 หลายเดือนก่อน
Use Arc and Mutex to update shared data with threads | Rust Language
Arc and Mutex - sharing ownership of data across threads | Rust Language
มุมมอง 1742 หลายเดือนก่อน
Arc and Mutex - sharing ownership of data across threads | Rust Language
Starting to learn Arc and Mutex | Rust Language
มุมมอง 4183 หลายเดือนก่อน
Starting to learn Arc and Mutex | Rust Language
Deref Trait | Rust Language
มุมมอง 6873 หลายเดือนก่อน
Deref Trait | Rust Language
Function Pointers | Rust Language
มุมมอง 1513 หลายเดือนก่อน
Function Pointers | Rust Language

ความคิดเห็น

  • @1____-____1
    @1____-____1 วันที่ผ่านมา

    Oh My God!! Someone actually using match in a demo.

    • @learning_rust
      @learning_rust 20 ชั่วโมงที่ผ่านมา

      To be honest, I try not to use unwrap at all now...feels a bit sloppy!

  • @1____-____1
    @1____-____1 2 วันที่ผ่านมา

    Is one action more expensive than the other?

    • @learning_rust
      @learning_rust วันที่ผ่านมา

      for_each is arguably less expensive in a typical case as you'd likely be using it where you won't require a new collection

  • @user-fe8hp6jv9f
    @user-fe8hp6jv9f 7 วันที่ผ่านมา

    Dam just realized that I have actually never learned how to do this in rust thanks.

    • @learning_rust
      @learning_rust 7 วันที่ผ่านมา

      Glad it helped. Rust keeps sure does keep us all humble as no matter how much progress you make you can never be sure you've not missed something really useful or important!!

  • @scottb4029
    @scottb4029 9 วันที่ผ่านมา

    I completely agree that you have to go over Rust again and again

    • @learning_rust
      @learning_rust 9 วันที่ผ่านมา

      100% Agree. It's not easy, a bit like doing a 1000 piece jigsaw puzzle, but as pieces fit together progress does speed up. eg. for loop implicitly calls into_iter() on a collection, I only fully understood this recently. I tend study from 2 books and then strip the examples right back to the minimum and memorise the part I want to really grasp. (Usually by typing it in from scratch once a day for a few days/weeks, a bit like learning a piece of music maybe?).

  • @gitikhekra
    @gitikhekra 11 วันที่ผ่านมา

    Please make video series on dioxus desktop app with surrealdb embedded..

    • @learning_rust
      @learning_rust 11 วันที่ผ่านมา

      Ok, thank you for suggestion, I will try. I did start to use and compile SurrealDB KV store with my iced project and my poor laptop took 12 mins to compile it. I'll see how Dioxus goes.

  • @riigel
    @riigel 19 วันที่ผ่านมา

    great video man, thanks for sharing this

    • @learning_rust
      @learning_rust 19 วันที่ผ่านมา

      My pleasure. Thanks for the comment, really helps with the dreaded algorithms 👍

  • @ariseyhun2085
    @ariseyhun2085 23 วันที่ผ่านมา

    Really cool video thank you for sharing! I've been working heavily with Leptos which has 0.7 coming out within the next month or so, would be cool to see a video covering the release notes perhaps :D

    • @learning_rust
      @learning_rust 23 วันที่ผ่านมา

      Thank you! @ariseyhun2085 - I'll take a look. Expect Chris Biscardi will cover it better than I can tbh, but may be able to find something to add!

  • @aqua-bery
    @aqua-bery 25 วันที่ผ่านมา

    Not the entirely unrelated AI woman in the intro 😭

    • @learning_rust
      @learning_rust 25 วันที่ผ่านมา

      I figured the Rust foundation won't sue me for using an AI woman! 😭

    • @ariseyhun2085
      @ariseyhun2085 23 วันที่ผ่านมา

      AI woman in intro, AI woman in profile pic, this guy likes AI women to say the least ;)

  • @gitikhekra
    @gitikhekra 26 วันที่ผ่านมา

    Nice! Please come up with videos on dioxus GUI and it's integration with embedded surrealdb .

  • @riigel
    @riigel 26 วันที่ผ่านมา

    nice! thanks for this

    • @learning_rust
      @learning_rust 26 วันที่ผ่านมา

      Thank you! - appreciate the kind comment!

  • @samdavepollard
    @samdavepollard 29 วันที่ผ่านมา

    agreed - nice book; subbed

    • @learning_rust
      @learning_rust 29 วันที่ผ่านมา

      Thanks for the sub, I still really rate the book - the 2nd half of it in particular.

  • @Heater-v1.0.0
    @Heater-v1.0.0 หลายเดือนก่อน

    Since the dawn of time the pointer to the next node in a linked list has been called "next". No confusion there.

    • @learning_rust
      @learning_rust หลายเดือนก่อน

      Thank you. I think maybe I've been tinkering with Bitcoin nodes too much, where there is a "previous block"

  • @sebastianmata9603
    @sebastianmata9603 หลายเดือนก่อน

    I thought that recursion was impossible in rust because of the ownership lol

    • @learning_rust
      @learning_rust หลายเดือนก่อน

      Yeah, you do need to use a Box pointer with link lists, but (so far) recursion is ok. This example was ok as all on the stack (i32) as I understand.

  • @flyingbluelion
    @flyingbluelion หลายเดือนก่อน

    a better issue for recursion is the memory and time overhead compared to direct code and what kinds of problems benefit form a recursive solution. "Towers of Hanoi" is a good example.

    • @learning_rust
      @learning_rust หลายเดือนก่อน

      Ah, yes, that's on the list, I'll delve into that in due course. My reason for looking at recursion is to understand and use trees more👍

  • @Tszyu01
    @Tszyu01 หลายเดือนก่อน

    This stream seems to run forever. Which can be great but how would you go about conditionally closing the live stream, let’s say closing the stream once it gets to rating 3.

    • @learning_rust
      @learning_rust หลายเดือนก่อน

      That's interesting question, I think there is a way to do it here : surrealdb.com/docs/surrealdb/integration/websocket#kill but you need the uuid, so you'd need to get that from a 'result' - "The UUID of the live query to kill" and then end the live query with the scope of the conditional logic that you add, eg "if rating > 3"

  • @nightire
    @nightire หลายเดือนก่อน

    I love the color scheme you used in Vim; what is it?

    • @learning_rust
      @learning_rust หลายเดือนก่อน

      Thank you! Plug 'catppuccin/nvim', { 'as': 'catppuccin' } and also I used the airline theme for the bar at the bottom with cattpucin as well.

  • @flyingbluelion
    @flyingbluelion หลายเดือนก่อน

    study Finite State Machines

  • @flyingbluelion
    @flyingbluelion 2 หลายเดือนก่อน

    Vectors have a function called reverse that reverses the order of elements in place :"v.reverse()"

  • @flyingbluelion
    @flyingbluelion 2 หลายเดือนก่อน

    Thanks, dude and keep going. I never knew this after studying Rust for a couple of YEARS!!

    • @learning_rust
      @learning_rust 2 หลายเดือนก่อน

      Glad I could help! I'm still leaning but just trying to make sure I investigate stuff as I come across it and make sure I could explain it. So much to learn!

  • @riigel
    @riigel 2 หลายเดือนก่อน

    good content, thanks!

    • @learning_rust
      @learning_rust 2 หลายเดือนก่อน

      You're welcome! Thanks for the kind comment 😊

  • @jeffg4686
    @jeffg4686 2 หลายเดือนก่อน

    With AI stuff, I forgot there even was a language called Rust. Is the Rust project still going?😂😂😂 We're going to be using GPT-Pilot and the like to write the whole app for us.

  • @jaymartinez311
    @jaymartinez311 2 หลายเดือนก่อน

    Random question. I saw the documentation to intergrate surrealdb by way of sdk with like a dotnet web api and it seemed like it eliminated the code for crud methods in a web api project, since it has built in functions that does that pretty efficiently and can be called directly vs using the frameworks methods. I’m confused if that’s on purpose or just an option? Also calling the entities directly like that when i’m use to using dtos to abstract the entities direct access and stuff. i know i could just create my own crud functions and wrap them around the surrealdb provided functions for more clarity but just confused a bit since surrealql is new but so simple to understand. I’m figuring some form of serialization must be done to not require dtos. I know this is a rust channel but this is more of a general backend question. Sorry for the long winded question.

    • @learning_rust
      @learning_rust 2 หลายเดือนก่อน

      Good question(s). To quote their docs "SurrealDB is designed to be run in many different ways, and environments. Due to the separation of the storage and API layers," So yes, seems like the built in functions eg the HTTP functions may be all you need, (JSON). As for creating your own CRUD functions, it seems like this is for where you want to run in embedded mode, eg incorporating in in memory database with your own project and this is where you need to deserialize the response, which is a bit more work. I'm fairly new to this also but am going to delve deeper. Thanks for the comment by the way!

  • @timClicks
    @timClicks 2 หลายเดือนก่อน

    Well done for taking my code and making it your own! Good luck with your learning journey :D

    • @learning_rust
      @learning_rust 2 หลายเดือนก่อน

      Thank you, I hope I gave proper credit to you for it! - Currently learning SurrealDB with Rust, would be interested to see you do a video on it if there is sufficient wider interest from other viewers 👍

  • @hlomphomota8055
    @hlomphomota8055 2 หลายเดือนก่อน

    Hard times...

  • @InMemoryOfNeo
    @InMemoryOfNeo 2 หลายเดือนก่อน

    👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏

  • @flyingbluelion
    @flyingbluelion 2 หลายเดือนก่อน

    In a real blockchain proof of work, the data to be hashed is a list of potential bitcoin transactions. Actually there are no transactions, all you can do is give bitcoin away. Thats's it.

    • @learning_rust
      @learning_rust 2 หลายเดือนก่อน

      Yes, this was obviously a dumbed down version, it was interesting nonetheless, especially making the difficulty go up by just 1 and how it affects the time to find an acceptable hash. The beauty is that it can be verified so easily?

  • @prophet6767
    @prophet6767 2 หลายเดือนก่อน

    The algorithm blessed me, good vid mate👍

    • @learning_rust
      @learning_rust 2 หลายเดือนก่อน

      Awesome, thank you!