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