Shouldn't pop return the element it pops off the list?
@cudidotdev4 ай бұрын
You are right. But after removing the element, nothing points to it, so it's dropped. It would be easier if the elements implement the clone trait. I had to do a general case scenario without using any unsafe block
@nordgaren23584 ай бұрын
@@cudidotdev why not return the RC. Would that work? I'm not at my PC right now. Liked list is an interesting problem in Rust for sure! I think you did a decent job at tackling it. :)
@cudidotdev4 ай бұрын
I think so. You can try and let me know
@LtdJorge3 ай бұрын
@@cudidotdevI think the best way is to do the if let Some on &self.head.take(). This way, you will get ownership of the RC. Then you can call &self.head.replace() with the value obtained by calling next.