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

Add a test to check stack overflow in "fist-drop" section #194

Open
tamuhey opened this issue May 23, 2021 · 3 comments
Open

Add a test to check stack overflow in "fist-drop" section #194

tamuhey opened this issue May 23, 2021 · 3 comments

Comments

@tamuhey
Copy link

tamuhey commented May 23, 2021

I think it is great to add a test to this section to cause stack overflow before implementing our own Drop.

@tamuhey tamuhey changed the title Add code to cause stack overflow in "fist-drop" section Add a test to check stack overflow in "fist-drop" section May 23, 2021
@kolulu23
Copy link

You can try this in the playground. refering to this post

@zenyusy
Copy link

zenyusy commented May 26, 2022

tried a bit: playground-2 versions of drop

found that without impl Drop the prog would go stack overflow; with either version of drop it can run successfully.

can i say that both versions of drop are correct ?

while let Some(mut b) = self.head.take() { self.head = b.next.take(); }
while let Some(b) = self.head.take() { self.head = b.next; }

@GuilhermoReadonly
Copy link

Hey @zenyusy !

I know it has been 2 years since your comment but I decided to follow and try this excellent book recently and was wondering the same question as you !!!

In my opinion this is equivalent and I found the second impl more elegant because shorter and without making "b" mutable but i also would like the opinion of a more seasoned Rust developer :)

Cheers and kudos to the authors of this book !

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

No branches or pull requests

4 participants