@syntacticsugarglider this isn't important cause I'm pretty sure I have a workaround, but it bugs me a lot that this doesn't work.

What would I even search to find out what is going wrong with the borrowchecker here
Do you know what its deal is? Does this case have a name or some objective criteria by which I could have anticipated that the borrow checker would have a problem with this prior to it yelling at me?

· · Web · 1 · 0 · 0

@faun I’ve got nothing so far, but I’m intrigued!

@faun I’m a bit hung up on where the Option is coming from

@flip last_mut gets a mutable reference to the last thing in the vector, but of course if the vector is empty it cannot do that, so in that case it would need to be able to return None

My issue is.. basically... if it finds out it's None.. it doesn't do anything with it, so the mutable borrow on level should be able to end, and it should be able to return level then.
But it can't :{

@faun If this works for you, I’d appreciate double points because I did it on my phone

@faun oh no it wouldn’t work because if assumes you’d be doing the first last_mut before calling but then it wouldn’t do it upon recursion D:

@faun @syntacticsugarglider because I knew the secret to Rust

It’s slapping the keyboard until the compiler is happy and then moving on and never thinking about it at all

@flip I did write something like that originally, I was hoping the recursive function would solve the lifetime issues.

@flip Though, in this case, I think the recursion can never go deeper than 6 or whatever because this is for building a table of contents from a markdown document and it can only go as deep as there are header html elements presumably.

Sign in to participate in the conversation

Merveilles is a community project aimed at the establishment of new ways of speaking, seeing and organizing information — A culture that seeks augmentation through the arts of engineering and design. A warm welcome to any like-minded people who feel these ideals resonate with them.