gmsol_solana_utils/utils/
with_slot.rs1#[derive(Debug, Clone, Copy)]
3pub struct WithSlot<T> {
4 slot: u64,
6 value: T,
8}
9
10impl<T> WithSlot<T> {
11 pub fn new(slot: u64, value: T) -> Self {
13 Self { slot, value }
14 }
15
16 pub fn slot(&self) -> u64 {
18 self.slot
19 }
20
21 pub fn slot_mut(&mut self) -> &mut u64 {
23 &mut self.slot
24 }
25
26 pub fn value(&self) -> &T {
28 &self.value
29 }
30
31 pub fn value_mut(&mut self) -> &mut T {
33 &mut self.value
34 }
35
36 pub fn into_value(self) -> T {
38 self.split().1
39 }
40
41 pub fn map<U>(self, f: impl FnOnce(T) -> U) -> WithSlot<U> {
43 WithSlot {
44 slot: self.slot,
45 value: (f)(self.value),
46 }
47 }
48
49 pub fn split(self) -> (u64, T) {
51 (self.slot, self.value)
52 }
53}
54
55impl<T, E> WithSlot<Result<T, E>> {
56 pub fn transpose(self) -> Result<WithSlot<T>, E> {
58 match self.value {
59 Ok(value) => Ok(WithSlot {
60 slot: self.slot,
61 value,
62 }),
63 Err(err) => Err(err),
64 }
65 }
66}