casper_storage/data_access_layer/
flush.rs

1use crate::global_state::error::Error as GlobalStateError;
2
3/// Request to flush state.
4pub struct FlushRequest {}
5
6impl FlushRequest {
7    /// Returns a new instance of FlushRequest.
8    pub fn new() -> Self {
9        FlushRequest {}
10    }
11}
12
13impl Default for FlushRequest {
14    fn default() -> Self {
15        FlushRequest::new()
16    }
17}
18
19/// Represents a result of a `flush` request.
20pub enum FlushResult {
21    /// Manual sync is disabled in config settings.
22    ManualSyncDisabled,
23    /// Successfully flushed.
24    Success,
25    /// Failed to flush.
26    Failure(GlobalStateError),
27}
28
29impl FlushResult {
30    /// Flush succeeded
31    pub fn flushed(&self) -> bool {
32        matches!(self, FlushResult::Success)
33    }
34
35    /// Transforms flush result to global state error, if relevant.
36    pub fn as_error(self) -> Result<(), GlobalStateError> {
37        match self {
38            FlushResult::ManualSyncDisabled | FlushResult::Success => Ok(()),
39            FlushResult::Failure(gse) => Err(gse),
40        }
41    }
42}