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
use super::*;

/// # Base shared by owned pointers
pub trait SparsePointer<S: DeserializeOwned + Serialize + SparsableTrait> {
    /// Get the inner value of the pointer
    fn get(&self) -> Result<SparseValue<'_, S>, SparseError>;
    /// Get the inner value of the pointer (mutable)
    fn get_mut(
        &mut self,
        state_cell: Rc<RefCell<SparseState>>,
    ) -> Result<SparseValueMut<'_, S>, SparseError>;
    /// Check if the inner value is outdated
    fn check_version(&self, state: &SparseState) -> Result<(), SparseError>;
    /// Reset the inner value and parse it again from the state
    fn self_reset(
        &mut self,
        state: &mut SparseState,
        metadata: &SparseMetadata,
        depth: u32,
    ) -> Result<(), SparseError>;
}

/// # Base shared by raw pointers
pub trait SparsePointerRaw<S: DeserializeOwned + Serialize + SparsableTrait> {
    /// Get the inner value of the pointer
    fn get<'a>(
        &'a self,
        metadata: Option<&'a SparseMetadata>,
    ) -> Result<SparseValue<'a, S>, SparseError>;
    /// Get the inner value of the pointer (mutable)
    fn get_mut<'a>(
        &'a mut self,
        state_cell: Rc<RefCell<SparseState>>,
        metadata: Option<&'a SparseMetadata>,
    ) -> Result<SparseValueMut<'a, S>, SparseError>;
    /// Check if the inner value is outdated
    fn check_version(&self, state: &SparseState) -> Result<(), SparseError>;
    /// Reset the inner value and parse it again from the state
    fn self_reset(
        &mut self,
        state: &mut SparseState,
        metadata: &SparseMetadata,
        depth: u32,
    ) -> Result<(), SparseError>;
}