Understanding Ownership in Rust

Understanding Ownership in Rust

Let's Get Rusty

3 года назад

265,116 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

@fennecfox2366
@fennecfox2366 - 27.08.2023 22:37

Coming from c++ this is intuitive. Unique pointers and move semantics give this type of behavior as options in modern c++ so having them as the default makes sense. Also having the const as default on refs is another good safety measure. I do think a basic understanding of pointers in c and references and smart pointers in c++ will help people understandownership and the ideas it's built upon.

Ответить
@sunilanthony17
@sunilanthony17 - 28.08.2023 03:10

This is so confusing. I will have to get back to this later.

Ответить
@kudorgyozo
@kudorgyozo - 17.09.2023 15:00

How/where are u executing a()?

Ответить
@hanshaun1350
@hanshaun1350 - 18.09.2023 18:34

This is BY FAR the hardest part to learn Rust. It's frustrating to learn without any C background tbh.

Ответить
@snippletrap
@snippletrap - 19.09.2023 00:31

In C++ you use std::unique_ptr and it auto-deletes when out of scope. Use of `new` is practically deprecated at this point.

Ответить
@kayakMike1000
@kayakMike1000 - 07.10.2023 20:16

I dunno, this seems like a pile of malarkey when proper message passing mechanism could be created in any language.

Ответить
@luckyraj8118
@luckyraj8118 - 27.10.2023 15:27

Thanks for the great website hosting info! Ive examined DreamHost and A2 Web Hosting, but Cloudways with TST20 coupon is the real gem.

Ответить
@macchiato_1881
@macchiato_1881 - 03.11.2023 05:00

"Get them tattooed, whatever it takes."

Don't threaten me with a good time buddy.

Ответить
@alexloktionoff6833
@alexloktionoff6833 - 11.11.2023 14:45

Can you help the beginner? Is there a possibility for borrow-checker to help to control partial structure updates? I mean can I pass the whole structure to the functions and in&out but borrow checker could help/nag in case called function changed a field value but the rest of the caller function code assumes the value has not been changed/updated? Can you show an example for the structure with the basic u32/int fields?

Ответить
@almuaz
@almuaz - 17.11.2023 09:44

I read the book and i was overwhelmed of new terms and information. this video helped me to visualize it live. yes rust book visualizations were great but for me i find this more helpful. i think after watching this, i will understand the book better. thank you.
there are too little learning resources for rust :)

Ответить
@recreationalplutonium
@recreationalplutonium - 21.11.2023 15:08

daning kruger the video

Ответить
@eileennoonan771
@eileennoonan771 - 07.12.2023 19:49

I am going to watch this every day until I understand it in my bones

Ответить
@quew9b
@quew9b - 11.12.2023 13:43

well, this one is not easy to understand. 😭

Ответить
@reactjs1900
@reactjs1900 - 16.12.2023 11:46

What is this b here ----- > if item == b' ' {
return i;
}

Ответить
@krishnababu5190
@krishnababu5190 - 26.12.2023 09:52

In C we have special memory (read only memory ) where string literlas are stored apart from stack and heap?
Do we have similar thing in rust (you mentioned string literals are stored in the binary ?)
could you help me out?

Ответить
@_pro_grammer_
@_pro_grammer_ - 15.01.2024 03:45

finally learning rust 💙

Ответить
@serkansunel
@serkansunel - 15.01.2024 10:41

is it a move or copy ? = is it a copy type or not ? = does it implement the copy trait or not ?

Ответить
@ronny332
@ronny332 - 26.01.2024 02:48

What I really like about your videos, until now :-), is the speed, you tell things. I'm not native American or English, but most every tutorial I watched for instance on Udemy was so slow. Of cause someone can speedup the video, but sometimes, the speaker speaks faster or changes slides, and that results in confusion.
Very, very well done, again until here 🙂as I don't know more of your videos besides the seen ones.

Ответить
@footballCartoon91
@footballCartoon91 - 27.01.2024 19:35

You do not explain specifically weather `&str` string slice or string literal is taken ownership by a function when it(the slice) enters it(the function). But I suppose the function does not take ownership because of `&` symbol.

Ответить
@thisisreallyme3130
@thisisreallyme3130 - 02.02.2024 16:01

Oh, this is VERY confusing if you are used to Python style of GC and you "just write code on the fly that works", no planning. Python and PHP encourages that kind of experimentation. When you get an error in Python it's always about the CURRENT line. And sometimes you get bugs without errors, like when you learn

What's helping me is: not trying to force rote memorization of 100% of this chapter. This isn't school where if you fail this chapter you are guaranteed to fail the next chapter. Just make sure you understand that Rust is performing static analysis. It's finding bugs that might never ever get triggered in your code, but could happen once someone else adds an innocent line of code later on (and now you get paged at 3AM).

If you understood enough of this to explain it on an elevator ride (quick and high level), maybe move on, you can always revisit this. Getting a compiler error later on isn't going to be total failure. I bet some people learn that way even though they tried to avoid it.

Ответить
@muratpinkman9679
@muratpinkman9679 - 12.02.2024 12:42

restriction

Ответить
@pratikdey8062
@pratikdey8062 - 17.02.2024 18:30

just wow

Ответить
@esmailhamdosh4390
@esmailhamdosh4390 - 12.03.2024 15:44

I asked chatgpt and it said that s2 points to the memory of the data of s1 instead of pointing to s1 and that the metdata of the string is stored in the heap can anyone enlighten me?

Ответить
@AndrewLighten
@AndrewLighten - 15.03.2024 07:30

Brilliant explanation. Thank you.

Ответить
@i_hope69
@i_hope69 - 20.03.2024 15:30

if you cannot remember the ownership rules then here is small trick i thought of which was :-
1) each house has a one owner
2) each house can have only one owner at a time
3) when owner dies the house is broken

Ответить
@LuisMateoAriasCaicedo
@LuisMateoAriasCaicedo - 22.03.2024 20:26

Thank you very much!

Ответить
@shavais33
@shavais33 - 26.03.2024 00:47

Slower write time than C++? I'm not learning rust because C++ isn't safe. I don't need help writing safe code. I'm learning Rust because I'm hoping I'll end up being able to get high performance software working in much less time than I can with C++.

I have a hypothesis about why it takes longer to create programs in C++ (for example) than it does in C# (for example) that is maybe a bit different from what most people seem to think.

It's illustrated by a story from experience. I was working on a game development project and I wanted to stream an .mp3 directly from an encrypted zip file. While working in C++, I found myself struggling with obscure errors and problems with the libraries I was using. I tried switching out libraries, switching my encryption and compression methods, I tried everything short of learning how to do encryption and compression and mp3 decoding from scratch myself to fix the problem.

After 2 or 3 weeks of this, I remembered a time when I was working at Intel. I once worked in a project group in which there was a developer working on getting a media viewer going. He was working in C++ and struggling with problems with libraries while working with the combination of compression, encryption, and audio/visual decoding. After 3 months, he still did not have it working. I joined that team near the end of it's multi-year effort. 6 or 8 months into my tenure on it, the team was disbanded and a separate group was given the project, who had been working on the same software in C# and had managed to get a working version together in about 4 months. (The whole thing, not just the audio-visual part.)

So I tried to get streaming this .mp3 from an encrypted zip file working in C#. Within a matter of hours I had it working. I was able to switch encryption and compression methods around and it still worked fine. No significant problems.

This really had nothing at all to do with syntax or memory management or borrow checking or anything at all like any of that! It was simply a matter of not struggling for weeks or months with obscure problems with external dependencies. That's it.

So I'm hoping that my code will perform at close to the speed of C++ and that when I go to use Rust packages, I'll find what I need, and I won't struggle with obscure problems with them for weeks or months on end. I don't care if it takes me a few minutes longer to write a function or a struct/class etc. I care if it takes me weeks or months longer to get functionality supposedly provided by external dependencies working.

Years ago I was scared off of Rust by the borrow checker and such, but was recently convinced to take another look when you said "These libraries aren't abandoned - they're Done." Yes, yes! And hopefully they actually work as advertised. This is what I'm hoping for from Rust.

I'm tempted to make this a Quora post. After I finish the early part of the learning process, maybe the first thing I'll do is try to get streaming an .mp3 directly from an encrypted zip file working in Rust and see how long it takes me. If I can do it in 3 days or less, I'll post this story to Quora, and mention your extremely helpful channel. (Thanks so much for doing this, by the way!)

Ответить
@kmaximoff
@kmaximoff - 26.03.2024 18:55

I was worried learning Rust, but more I look at this. THIS MAKES SO MUCH SENSE!

Ответить
@SahilVyas-n2l
@SahilVyas-n2l - 16.04.2024 20:09

Which extensions you are using in vscode?

Ответить
@Christobanistan
@Christobanistan - 25.04.2024 14:14

This is by far the toughest part of Rust. I really wish the book had a ton more examples and explained things far better.

Ответить
@ildani1658
@ildani1658 - 08.05.2024 20:02

If I may
Very good video! but your voice makes me sleep :( ...

Ответить
@salocin74
@salocin74 - 01.06.2024 16:00

Hey! Love the videos, thanks so much for producing and sharing these!

Just wanted to let you know that the flag in the background is backwards. Should always be displayed with the starts in the top left, even when displayed vertically!

Ответить
@nowarm
@nowarm - 07.06.2024 19:23

Thank you for making this. It's so helpful and so easy to follow along. You're amazing

Ответить
@MT-xb3ts
@MT-xb3ts - 11.06.2024 18:31

What is a Shtring?

Ответить
@a.paudel1301
@a.paudel1301 - 26.06.2024 15:01

I love you, This is awesome.

Ответить
@brennancurrier806
@brennancurrier806 - 03.07.2024 23:36

Video form of the book helps me so much, I read really slow, you covered the entire chapter in 25 min shorter than I could probably read it lol.

Ответить
@sweetjimmy
@sweetjimmy - 18.07.2024 17:02

in the Stack & Heap section, why was "hello" not stored in heap?

Ответить
@rohandvivedi
@rohandvivedi - 21.08.2024 17:06

This is the best explanation,
I have come across.

Ответить
@fr0xk
@fr0xk - 30.10.2024 11:28

Now as mojo is new cool language that's easy to learn, safe and fast on bare metal, and entered TIOBE Top 50 index, Rust needs to offer something new lol

Some game programmers attached to 6502, Z80, and 68000 Assembly say C is slow and leads to messy code. C developers then criticize C++. I think garbage collection has its place in games—just look at Minecraft and Roblox. With hardware improving, latency and RAM wasn’t the major issue it once was. Languages like C, Rust, and Zig serve very very specialized purposes, but the fixation on keeping latency under 0.1 seconds seems a bit overblown. In many real-world scenarios, network delays and task scheduling usually take longer. Manual memory management might be important for real-time systems, but it feels less relevant for typical personal computing. I also see some challenges with Rust. Cargo piles on dependencies for very simple programs, and the borrow checker adds cost on compile times. Adjusting to ownership and borrowing concepts is something I also consider as cost. Rust is definitely not zero cost in absolute sense

Ответить
@jasdfpasdfakdsjhfa
@jasdfpasdfakdsjhfa - 04.11.2024 05:48

You forgot about one memory management model! Pure functional immutability, where everything is on the stack and passed by value.

Ответить
@Deepz007
@Deepz007 - 05.11.2024 21:41

I am new to Rust, read ownership chapter twice, got the concepts of ownership, reference and moves but still wasn't confident. This video did the trick and made everything crystal clear. Thanks a ton!

Ответить