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
use core::cell::Cell;
use crate::{Fields, Field};
pub trait CellExt {
type Inner;
fn project<T>(&self, field: Field<Self::Inner, T>) -> &Cell<T>;
}
impl<S: Fields> CellExt for Cell<S> {
type Inner = S;
fn project<T>(&self, field: Field<S, T>) -> &Cell<T> {
unsafe {
let offset = S::OFFSETS[field.index()](self.as_ptr() as *mut _);
let field = (self as *const _ as *const u8).add(offset);
&*(field as *const Cell<T>)
}
}
}