The first line drops the original string contained in current_context so at this moment tokens is referring to the freed memory. The existence of the dangling reference is considered to be an undefined behavior, this code should be fixed. Store the string in a local variable, assign the refeference first, then assign the context.
Also we can probably use Box::leak() to get &’static str and can remove transmute() s.
https://github.com/statiolake/proconio-rs/blob/1e72f67b3420d61a0ee8cae922e55c5d0db89227/proconio/src/source/line.rs#L53-L54
The first line drops the original string contained in
current_context
so at this momenttokens
is referring to the freed memory. The existence of the dangling reference is considered to be an undefined behavior, this code should be fixed. Store the string in a local variable, assign the refeference first, then assign the context.Also we can probably use
Box::leak()
to get&’static str
and can removetransmute()
s.