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
use std::ops::{Deref, DerefMut};

use crate::*;

#[derive(Debug)]
pub struct Caller<T> {
    store: Store<T>,
}

impl<T> Caller<T> {
    pub(crate) fn new(handle: DataHandle<T>) -> Self {
        Self {
            store: Store::from_handle(handle),
        }
    }

    pub fn data(&self) -> impl Deref<Target = T> + '_ {
        self.store.data()
    }

    pub fn data_mut(&mut self) -> impl DerefMut<Target = T> + '_ {
        self.store.data_mut()
    }
}

impl<T> Clone for Caller<T> {
    fn clone(&self) -> Self {
        Self {
            store: self.store.clone(),
        }
    }
}

impl<T> AsContext for Caller<T> {
    type Data = T;

    fn as_context(&self) -> &Store<Self::Data> {
        &self.store
    }
}

impl<T> AsContextMut for Caller<T> {
    fn as_context_mut(&mut self) -> &mut Store<Self::Data> {
        &mut self.store
    }
}