Why does Rust check borrow even in single thread
Posted 金庆
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Why does Rust check borrow even in single thread相关的知识,希望对你有一定的参考价值。
Why does Rust check borrow even in single thread
(Jin Qing’s Column, Aug. 7, 2021)
The Rust book says borrow checking is to prevent data race.
But the borrow checker forbids multiply mutable borrows even in the same thread.
Is there data race in single thread?
Why does the borrow checker forbid it in the same thread?
The Problem With Single-threaded Shared Mutability
answers this question.
It gaves 2 cases that shared mutability causes prolem.
One is Rust enum variable, which can has different inner type.
If the inner type changed, the references to the old data would be invalidated.
Another case is Iterator invalidation that the container’s change can invalidate the Iterator.
以上是关于Why does Rust check borrow even in single thread的主要内容,如果未能解决你的问题,请参考以下文章
Why does OpenCV use BGR color format ?
Why SignalR does not use WebSockets?
Why does my Authorize Attribute not work?
What is DevOps anyway and why does it matters?
why does it suck to be an in-house programmer?
Why does Delphi XE7 IDE hangs and fails on out of memory exception?