barter_integration/
snapshot.rs

1use derive_more::{Constructor, From};
2use serde::{Deserialize, Serialize};
3
4#[derive(
5    Debug,
6    Clone,
7    Copy,
8    Eq,
9    PartialEq,
10    Ord,
11    PartialOrd,
12    Hash,
13    Deserialize,
14    Serialize,
15    Constructor,
16    From,
17)]
18pub struct Snapshot<T>(pub T);
19
20impl<T> Snapshot<T> {
21    pub fn value(&self) -> &T {
22        &self.0
23    }
24
25    pub fn as_ref(&self) -> Snapshot<&T> {
26        let Self(item) = self;
27        Snapshot(item)
28    }
29
30    pub fn map<F, N>(self, op: F) -> Snapshot<N>
31    where
32        F: Fn(T) -> N,
33    {
34        let Self(item) = self;
35        Snapshot(op(item))
36    }
37}
38
39#[derive(
40    Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Deserialize, Serialize, Constructor,
41)]
42pub struct SnapUpdates<Snapshot, Updates> {
43    pub snapshot: Snapshot,
44    pub updates: Updates,
45}