These are chat archives for rust-lang/rust

14th
Oct 2016
kalebo
@kalebo
Oct 14 2016 00:07
So I'm trying to figure out rust macros to have a succinct way of declaring maps in my unit tests. My best attempt is here: https://is.gd/uEiwYB Could anyone give me a few pointers on why it's not working?
saolof
@saolof
Oct 14 2016 00:08
what is the key advantage of box over normal borrows?
Tyred
@tyred
Oct 14 2016 00:11
Heap allocation I think
saolof
@saolof
Oct 14 2016 00:11
ah ok, still a bit confused over stack vs heap when pointers are involved
Michael Howell
@notriddle
Oct 14 2016 00:22
Box isn't a borrow. Boxes own the underlying type.
When a box is destroyed, the underlying data is destroyed, too.
That's pretty much the only difference between a box and a reference.
Tyred
@tyred
Oct 14 2016 00:25
Box takes ownership of the data that is contained in
Michael Howell
@notriddle
Oct 14 2016 00:26
Exactly. When a reference gets dropped, nothing happens. When a box gets dropped, the value it points at gets dropped, and then the memory is freed.\
A reference can point anywhere, while a box only points at the heap. You don't want to try to return memory to the allocator if that's not where it came from.
As for Box vs. non-boxed data, the difference is between heap and stack allocation.
Tyred
@tyred
Oct 14 2016 00:30
Thats what I was getting at towards the end heh.
Thanks for the explanation, hopefully that helps @saolof
saolof
@saolof
Oct 14 2016 02:13
This mostly cleared things up, thanks!
Arthur Silva
@arthurprs
Oct 14 2016 09:51
@kalebo you need to insert ; between the insertions, and also return the _map from the { } block
kalebo
@kalebo
Oct 14 2016 13:27
@arthurprs thanks a million! I feel sorta stupid for not catching that before.
Arthur Silva
@arthurprs
Oct 14 2016 13:36
:smile: