Тёмный

The Why, What, and How of Pinning in Rust 

Jon Gjengset
Подписаться 87 тыс.
Просмотров 72 тыс.
50% 1

Опубликовано:

 

30 сен 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 38   
@mageprometheus
@mageprometheus 4 года назад
I wrote my first program in the late 70s so I’ve been learning new languages for quite a while. Your advanced videos are great because the pain seems to drive my old brain to become more plastic. I suppose its the masochistic method of understanding. Thank you so much for this resource Jon.
@samuelhurel6402
@samuelhurel6402 5 лет назад
Sound is gorgeous! Thanks a lot to whoever gifted you this microphone!
@iwikal
@iwikal 3 года назад
2:12:10 Automatically implementing Unpin for async blocks and functions that don't need pinning is probably something that could cause problems for API stability. If a library author exposes an async function that gets impl Unpin automatically because it doesn't currently have any self-references, if they want to change the implementation to something that isn't Unpin, that would be a breaking change.
@bigdog-t3k
@bigdog-t3k Год назад
That’s a pretty great point about API stability. This actually does cause problems with Send and Sync because they are automatically implemented for async blocks depending on the block’s content. So the API contract of an async function’s return type can change purely based on its body. I’ve encountered this before in a backend project where I used an itertools group_by function, which for some reason isn’t Send, in an async function. Didn’t hit any compiler errors while I was working on that crate, then when I tried to run the server there I got a gnarly error because the fully composed futures returned from the server’s router functions weren’t Send and that’s no bueno with tokio. And additionally, even if you don’t hold those !Send types across await points, the async block generated is still !Send. That’s what’ll really trip you up.
@xoomayose
@xoomayose 5 лет назад
I think that an easier way to see why Pin is important is with a simple struct like struct Packet { skb: [u8; 512], header: &'skb [u8], body: &'skb [u8], } `header` and `body` are slices to bytes in `skb`. Using futures as an example of self-referential structs can be confusing, because they contain much more details.
@matthiask1637
@matthiask1637 5 лет назад
So skb needs to be pinned?
@jonhoo
@jonhoo 5 лет назад
So, this is what I was trying to get at with the Parsed example :) But more examples is helpful!
@a_commenter
@a_commenter Год назад
@@jonhoo I liked the Parsed example, but I feel like you moved off of it too quickly before you really got into the meat of Pin
@alexwhite6133
@alexwhite6133 4 года назад
Wow, what a guy. Enormous knowledge paired with understandable explanation. Now I know what it really means to be a programmer! Jon, thanks for the videos and your time. Unbelievable...
@SouravSingh-zr6dx
@SouravSingh-zr6dx Год назад
Hi Jon , Just want to say thank you for sharing all this knowledge with us. You are amazing man🙏
@ezengondolkozom3700
@ezengondolkozom3700 5 лет назад
God your vim looks orgasmically good.
@swfsql
@swfsql 3 года назад
In 1:26:20, shouldn't this only be unsound if you actually called a _poll()_ on _x_ after you created it? Because if you pin and still _mem::replace()_ it, you didn't yet actually depended on that pinning right? btw you often explicitly inserted _poll()_ calls around some _mem::replace()_ after pinning, so I wondered if in this case you didn't? (Thx for the explanation!! XD)
@Mrgreatestfreakout
@Mrgreatestfreakout 3 года назад
Hey Jon! Always appreciate your videos hehe...question about your real-time compile messages(?) that you get in vim. What did you install? I'm using jetbrain rust plugin but you only get detailed error only when you compile
@benmuker6300
@benmuker6300 5 лет назад
from my understanding, the only reason, why pinning is neccessary is, because it is forbidden to move a struct, that contains a pointer to a field of itself, because that move does not change the value of the pointer and so the pointer points to the old memory location ando nobody knows about its contents anymore. But if i used a relative pointer instead, would that get rid of the problem, because when i move the struckt with the (relative) pointer to a field of itself, the relative pointer now still points to the currect location, because the layout of the struct does not change. I think that I overlook someting so please clarify me
@jonhoo
@jonhoo 5 лет назад
Ah, so, in the specific case where the target of the pointer is stored within the struct, that's fine, but in the general case, relative pointers are not sufficient. For example, consider a struct that holds a Vec (so a heap-allocated vector) and a type with pointers into that Vec. There's no relative pointer you can use there to make moves okay
@XiaoZhang-x1a0
@XiaoZhang-x1a0 4 года назад
@@jonhoo Hi. If the Vec is on heap, moving the struct will not move the Vec so the pointer should be still valid?
@iwikal
@iwikal 3 года назад
@@XiaoZhang-x1a0 In the case of a Vec, relative pointers hurt rather than help because when you move the struct, the Vec's buffer stays in place on the heap, so relative pointers into it are no longer valid. If you used absolute pointers, mutating the Vec risks invalidating them, because it might reallocate or simply drop entries you're pointing to.
@astrolemonade349
@astrolemonade349 5 лет назад
What linux distro are you using ? How do you make the menus and everything be at bottom ?
@jonhoo
@jonhoo 5 лет назад
I have a video on that over at ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-ycMiMDHopNc.html&lc=Ugw7mC8ZYKfWnJwL9Tx4AaABAg :)
@jeffg4686
@jeffg4686 3 года назад
Good stuff, thanks for sharing. How do you know when you should "take" a value from an option rather than just unwrapping it. I know it's about ownership, but don't really understand why the necessity. Is this basically saying that the function call the taken value is passed to is a pass by value semantics, and can't take a borrow/ref so is required in this case, or is there more to it? I see this occasionally and always confused me. In this video, referencing code at 46:37 - self.value.take().unwrap() . Thanks for any thoughts.
@jonhoo
@jonhoo 3 года назад
You use take if you want to leave None behind in the Option that you're calling take on. unwrap() on the other hand consumers the Option, and makes it so that it cannot be used by anyone ever again.
@dbrgn
@dbrgn 4 года назад
Thanks Jon, this is really really helpful.
@wayneashleyberry
@wayneashleyberry 5 лет назад
This new microphone sounds fantastic!
@DHorse
@DHorse 3 месяца назад
Thanks Jon. The implementation was quite challenging but an essential topic. You pinned it! ... I mean nailed it!
@encody
@encody 2 года назад
Dude, thank you so much for this video. I work with Rust professionally and I'm in awe of your expertise.
@kshitijjain8544
@kshitijjain8544 3 года назад
At 55:44, you say because FooFuture is not DerefMut. Did you mean to say FooFuture is not Unpin?
@zaooo
@zaooo 5 лет назад
Caution for viewers with ears, there's a loud mic thud at 2:26:09.
@jonhoo
@jonhoo 5 лет назад
Yeah, I've added a shock mount to my wish list to deal with some of those kinds of issues. The new mic also picks up keyboard sounds more than the old one did, which the shock mount should also help with.
@DHorse
@DHorse 4 года назад
Thanks, no problem. The lid on the jar is tightly sealed.
@matthiasdebernardini3388
@matthiasdebernardini3388 Год назад
this video is so good, thanks so much for sharing - its just what I needed!
@lukekhamilton
@lukekhamilton 4 года назад
What's your vimrc config bro? Feel things I want to check out here! Thanks :)
@jonhoo
@jonhoo 4 года назад
I go through my setup in a decent amount of details here: ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-ycMiMDHopNc.html. My full configs are here: github.com/jonhoo/configs
@xthebumpx
@xthebumpx 5 лет назад
But the real important question is: how you get the address bar/tabs on firefox at the bottom of the window?
@jonhoo
@jonhoo 5 лет назад
I actually go through my whole desktop setup in ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-ycMiMDHopNc.html :)
@bocckoka
@bocckoka 3 года назад
moving a Pin refers to passing on ownership or relocating in memory?
@jadonbelezos2583
@jadonbelezos2583 3 года назад
as i understand it which maybe wrong your passing ownership. the actual self referential struct hasnt been moved. just the owning pointer/mutable reference has!
@theodimopoulos8039
@theodimopoulos8039 5 лет назад
Thx vm!
Далее
Considering Rust
1:03:57
Просмотров 191 тыс.
Self-referential structs (in Rust)
27:21
Просмотров 54 тыс.
Трудности СГОРЕВШЕЙ BMW M4!
49:41
Просмотров 1,7 млн
Crust of Rust: Send, Sync, and their implementors
1:07:04
8 deadly mistakes beginner Rust developers make
14:14
Просмотров 168 тыс.
Rust: Error Handling
19:16
Просмотров 15 тыс.
Crust of Rust: Functions, Closures, and Their Traits
1:06:40
Crust of Rust: Iterators
1:26:27
Просмотров 100 тыс.
Impl Trait aka Look ma’, no generics! by Jon Gjengset
1:09:05
1 Hour Dive into Asynchronous Rust
1:14:12
Просмотров 20 тыс.
Crust of Rust: Lifetime Annotations
1:33:23
Просмотров 215 тыс.