object_rainbow/
local_fetch.rs1use crate::*;
2
3#[pod]
4pub struct Local<T>(pub T);
5
6impl<T> Deref for Local<T> {
7 type Target = T;
8
9 fn deref(&self) -> &Self::Target {
10 &self.0
11 }
12}
13
14impl<T> DerefMut for Local<T> {
15 fn deref_mut(&mut self) -> &mut Self::Target {
16 &mut self.0
17 }
18}
19
20impl<T: Traversible + Clone> Fetch for Local<T> {
21 type T = T;
22
23 fn fetch(&'_ self) -> FailFuture<'_, Self::T> {
24 Box::pin(ready(Ok(self.0.clone())))
25 }
26
27 fn try_fetch_local(&self) -> object_rainbow::Result<Option<Self::T>> {
28 Ok(Some(self.0.clone()))
29 }
30
31 fn fetch_local(&self) -> Option<Self::T> {
32 Some(self.0.clone())
33 }
34
35 fn get(&self) -> Option<&Self::T> {
36 Some(&self.0)
37 }
38
39 fn get_mut(&mut self) -> Option<&mut Self::T> {
40 Some(&mut self.0)
41 }
42
43 fn try_unwrap(self: Arc<Self>) -> Option<Self::T> {
44 Arc::try_unwrap(self).ok().map(|Self(object)| object)
45 }
46}
47
48impl<T: Traversible> FetchBytes for Local<T> {
49 fn fetch_bytes(&'_ self) -> FailFuture<'_, ByteNode> {
50 Box::pin(ready(Ok(self.0.byte_node())))
51 }
52
53 fn fetch_data(&'_ self) -> FailFuture<'_, Vec<u8>> {
54 Box::pin(ready(Ok(self.0.vec())))
55 }
56
57 fn fetch_bytes_local(&self) -> object_rainbow::Result<Option<ByteNode>> {
58 Ok(Some(self.0.byte_node()))
59 }
60
61 fn fetch_data_local(&self) -> Option<Vec<u8>> {
62 Some(self.0.vec())
63 }
64}
65
66impl<T: Traversible> Singular for Local<T> {
67 fn hash(&self) -> Hash {
68 self.0.full_hash()
69 }
70}
71
72impl<T> From<T> for Local<T> {
73 fn from(object: T) -> Self {
74 Self(object)
75 }
76}