It talks about people can use Weak Instead of Rc to avoid Reference Cycle problem. But it doesn't provide a Weak implementation. Thus I tried to do it by myself.
Since I am a newbie, I might be completely wrong. Here is my implementation: Rust Playground
Since it's a infinite cycle, I tried to print 5 tails in a loop.
If I only print one tail without the for loop, it works fine.
But inside the loop, the compiler will complain borrowed value does not live long enough. It seems the borrowed value can not be used inside a loop.
I tried to fix the problem for a whole day and tried many things including using global variables. But none of the trials works.
If you want to learn how to write a linked-list properly (which itself is a fairly difficult thing to do in Rust, given its type system), you can read this book. It will clear up all your doubts and teach you a bunch of new things as well.
It won't help to fix that loop, since it seems to me that you haven't yet understood how Rc and Weak work. But I think the book will clear that up.
Thank you very much for introducing the book. I will read it after completing the first rust book and async book.
Btw, I really want to make that loop work because I have spent an entire day to fight with that loop...
From what I understand, the problem is list.tail()'s list dropped in the first loop cycle, but _link.borrow().upgrade() will need to use that dropped value in the second loop cycle. I am not sure if what I understand is correct or not. I have no ideas how to fix it.