Skip to main content

sark_http/owner/
effect.rs

1use o3::buffer::hold;
2
3use crate::owner::Change;
4
5/// One indivisible response-owner mutation. Handoff transfers the
6/// owner from protocol staging to transport.
7#[must_use = "owner effects must be committed to their lifecycle sink"]
8#[derive(Clone, Copy, PartialEq, Eq, Hash)]
9pub struct Effect<K> {
10    key: K,
11    charge: hold::Charge,
12    change: Change,
13}
14
15impl<K> Effect<K> {
16    pub const fn new(key: K, charge: hold::Charge, next: Change) -> Self {
17        Self {
18            key,
19            charge,
20            change: next,
21        }
22    }
23
24    pub const fn key(&self) -> &K {
25        &self.key
26    }
27
28    pub const fn charge(&self) -> hold::Charge {
29        self.charge
30    }
31
32    pub const fn change(&self) -> Change {
33        self.change
34    }
35
36    pub fn map_key<T>(self, map: impl FnOnce(K) -> T) -> Effect<T> {
37        Effect {
38            key: map(self.key),
39            charge: self.charge,
40            change: self.change,
41        }
42    }
43}