Hi all,
last week I have encoutered an amazing example explaining lifetime and reborrowing.
I didn't save the page, and been searching it ever since without success. I am not sure if this is in this forum, stack overflow, or any other online article.
The structure of the example was something like this:
fn foo()
{
let mut x = 3;
let rx = &mut x;
{
some code
some code
}
some code // line 1
some code // line 2
}
Now, the cool part was that when including the block bracket '{', '}', only line 1 compiles and line 2 raises a compilation error. And when commenting out the block brackets (and keeping all other code, including the code in the block, as is), only line 2 compiles and line 1 raises an error.
It was an amazing example showcasing lifetime and reborrowing, but for the life of me I coulnd't find it again. I tried using AI to generate the code or to find the link, but no luck so far.
// case 1
fn foo()
{
let mut x = 3;
let rx = &mut x;
{
some code
some code
}
some code // line 1
//some code ==> line 2 : error
}
// case 2
fn foo()
{
let mut x = 3;
let rx = &mut x;
//{
some code
some code
//}
//some code ==> line 1 : error
some code // line 2
}
Does someone recognize this example?
Thanks