1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/*
* Copyright (c) godot-rust; Bromeon and contributors.
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
//! # Internal crate of [**godot-rust**](https://godot-rust.github.io)
//!
//! Do not depend on this crate directly, instead use the `godot` crate.
//! No SemVer or other guarantees are provided.
//!
//! # Contributor docs
//!
//! A re-entrant cell implementation which allows for `&mut` references to be reborrowed even while `&mut`
//! references still exist.
//!
//! This is done by ensuring any existing `&mut` references cannot alias the new reference, and that the new
//! reference is derived from the previous one.
//!
//! This emulates Rust's system for function calls; i.e. `my_func(&mut borrowed)` creates a second `&mut` reference inside the function.
//!
//! Instead of directly using the concept of _aliasing_ pointers, we use the term _accessible_ instead. A
//! reference (or other pointer) to some value is considered accessible when it is possible to either read
//! from or write to the value it points to without using `unsafe`. Importantly, if we know that a reference
//! `a` is inaccessible, and then we create a new reference `b` derived from `a` to the same value, then we
//! know for sure that `b` won't alias `a`. This is because aliasing in Rust is based on accesses, and if we
//! never access `a` then we cannot ever violate aliasing for `a` and `b`. And since `b` is derived from `a`
//! (that is, `b` was created from `a` somehow such as by casting `a` to a raw pointer then to a reference
//! `b`), then `a` won't get invalidated by accesses to `b`.