geo-ant / blog

My public notepad in blog form
https://geo-ant.github.io/blog
MIT License
1 stars 0 forks source link

Deep Dive: dyn Trait Objects and Vtables in Rust #46

Open geo-ant opened 1 year ago

geo-ant commented 1 year ago

comments for the article go here

zeenix commented 1 year ago

Great post!

I think the "former" and "latter" are inverted in the paragraph about pointers and fat pointers? 🤔

from from the pointer types Box, &dyn Trait, and &mut dyn Trait. While the former are really just pointers 8, the latter are also fat pointers.

Also I not noticed a typo: extra "from".

geo-ant commented 1 year ago

Thank you kindly @zeenix. I removed the duplicate from. I'm not a native speaker and I looked up the former / latter thingy again and I believe I used it correctly. If you think the phrasing is unclear, I'll try and come up with something better.

zeenix commented 1 year ago

You got it! I think the confusing bit (for me at least) was that Box isn't a pointer. Maybe it's just my C background overshadowing my Rust knowledge but I think only references can be called pointers. 🤔

zeenix commented 1 year ago

In any case this small correction will make things clearer: "former are" -> "former is".

geo-ant commented 1 year ago

You got it! I think the confusing bit (for me at least) was that Box isn't a pointer. Maybe it's just my C background overshadowing my Rust knowledge but I think only references can be called pointers. 🤔

Hey, I'll think of a way to rephrase that parapraph, I think it's confusing after all.

One more thing though. And I am honestly not trying to argue with you, just trying to understand your point and I really appreciate that you took the time to comment. Why do you not consider Box a pointer? The rust doc calls it a pointer type. Is it because it contains more members than just the raw pointer (i.e. the allocator)?

zeenix commented 1 year ago

One more thing though. And I am honestly not trying to argue with you, just trying to understand your point and I really appreciate that you took the time to comment.

Don't worry about it. It'd be perfectly fine to argue. :) I try not to take things personally. We're all just learners here w/ different way of looking at things.

Why do you not consider Box a pointer? The rust doc calls it a pointer type. Is it because it contains more members than just the raw pointer (i.e. the allocator)?

No. I guess it boils down to the fact that I think there is a difference between pointer type and pointer. I'd consider Box (as well as Arc, Rc, Cell etc) pointer types but not pointers. E.g here:

struct Str<'a> {
    pointer: &'a str,
}

I'd call Str a pointer type but not a pointer, while I'd call Str::pointer a pointer. I hope that clarifies things. :+1:

geo-ant commented 1 year ago

I understand and that makes sense. I'll try to rephrase the paragraph, but I still have to consolidate how I think about these things. Thanks for taking the time to discuss this. I hope the Rust community will stay as welcoming and positive even as it grows more :)