A comparison of Rust’s borrow checker to the one in C#
em-tg
Wait, C# has a borrow checker?
Behold: the classic example of rust’s zero-cost memory safety…
// error[E0597]: `shortlived` does not live long enough
let longlived = 12;
let mut plonglived = &longlived;
{
let shortlived = 13;
plonglived = &shortlived;
}
*plonglived;
…ported to C#:
// error CS8374: Cannot ref-assign 'shortlived' to 'plonglived' because
// 'shortlived' has a narrower escape scope than 'plonglived'
var longlived = 12;
ref var plonglived = ref longlived;
{
var shortlived = 13;...
Read more at em-tg.github.io