]> git.lizzy.rs Git - rust.git/blob - src/stacked_borrows.rs
dd9f1b370890d85cbe21d23a1d8ecd14e05fa629
[rust.git] / src / stacked_borrows.rs
1 use super::RangeMap;
2
3 pub type Timestamp = u64;
4
5 /// Information about a potentially mutable borrow
6 #[derive(Copy, Clone, Debug, Hash, PartialEq, Eq)]
7 pub enum Mut {
8   /// A unique, mutable reference
9   Uniq(Timestamp),
10   /// Any raw pointer, or a shared borrow with interior mutability
11   Raw,
12 }
13
14 /// Information about any kind of borrow
15 #[derive(Copy, Clone, Debug, Hash, PartialEq, Eq)]
16 pub enum Borrow {
17   /// A mutable borrow, a raw pointer, or a shared borrow with interior mutability
18   Mut(Mut),
19   /// A shared borrow without interior mutability
20   Frz(Timestamp)
21 }
22
23 /// An item in the borrow stack
24 #[derive(Copy, Clone, Debug, Hash, PartialEq, Eq)]
25 pub enum BorStackItem {
26   /// Defines which references are permitted to mutate *if* the location is not frozen
27   Mut(Mut),
28   /// A barrier, tracking the function it belongs to by its index on the call stack
29   FnBarrier(usize)
30 }
31
32 impl Default for Borrow {
33     fn default() -> Self {
34         Borrow::Mut(Mut::Raw)
35     }
36 }