gpt4 book ai didi

rust - 为什么 `*mut T` 实现 `Unwindsafe` 而 `&mut T` 没有?

转载 作者:行者123 更新时间:2023-12-03 11:25:01 26 4
gpt4 key购买 nike

documentationUnwindsafe我们有:

Types such as &mut T and &RefCell<T> are examples which are not unwind safe. The general idea is that any mutable state which can be shared across catch_unwind is not unwind safe by default. This is because it is very easy to witness a broken invariant outside of catch_unwind as the data is simply accessed as usual.



按照这个逻辑,在我看来 *mut T不应该是 Unwindsafe .但是 it turns out that it is .这是为什么?

最佳答案

*mut T作为一个原始指针,它没有任何不变性。

可以为null,指向无效内存,为Copy ,并且您可以让其中两个指向内存中的同一区域。

使用 *mut T,您无能为力且安全无虞。无论如何,所以没有理由不成为Unwindsafe .

关于rust - 为什么 `*mut T` 实现 `Unwindsafe` 而 `&mut T` 没有?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62422474/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com