Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inaccuracy in 15-1 #606

Closed
djzin opened this issue Apr 6, 2017 · 2 comments
Closed

Inaccuracy in 15-1 #606

djzin opened this issue Apr 6, 2017 · 2 comments
Labels
Milestone

Comments

@djzin
Copy link

djzin commented Apr 6, 2017

Because a Box<T> is a pointer, we always know how much space it needs: a
pointer takes up a usize amount of space.

since a box always has the size of a usize, no matter what it's pointing to

These are false statements. For example,

assert_eq!(std::mem::size_of::<Box<str>>(), std::mem::size_of::<usize>() * 2);
assert_eq!(std::mem::size_of::<Box<ToString>>(), std::mem::size_of::<usize>() * 2);

It would be nice to clarify this (maybe in a footnote) whilst keeping it simple for purposes of the example.

@carols10cents
Copy link
Member

Ooooops. Yeah, I'll reword this next time we get this chapter back from nostarch so that at least it's not incorrect. Thanks!!! ❤️

@steveklabnik
Copy link
Member

So, a box on its own is always a usize. A trait object isn't just a box.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants