-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
57 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,6 @@ | |
mod r#type; | ||
pub use r#type::*; | ||
|
||
mod validity; | ||
pub use validity::BatchValidity; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
//! Contains the [BatchValidity] and its encodings. | ||
/// Batch Validity | ||
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] | ||
#[derive(Debug, Clone, Copy, PartialEq, Eq)] | ||
pub enum BatchValidity { | ||
/// The batch is invalid now and in the future, unless we reorg | ||
Drop, | ||
/// The batch is valid and should be processed | ||
Accept, | ||
/// We are lacking L1 information until we can proceed batch filtering | ||
Undecided, | ||
/// The batch may be valid, but cannot be processed yet and should be checked again later | ||
Future, | ||
/// Introduced in Holocene, a special variant of the Drop variant that signals not to flush | ||
/// the active batch and channel, in the case of processing an old batch | ||
Past, | ||
} | ||
|
||
impl BatchValidity { | ||
/// Returns if the batch is accepted. | ||
pub const fn is_accept(&self) -> bool { | ||
matches!(self, Self::Accept) | ||
} | ||
|
||
/// Returns if the batch is dropped. | ||
pub const fn is_drop(&self) -> bool { | ||
matches!(self, Self::Drop) | ||
} | ||
|
||
/// Returns if the batch is outdated. | ||
pub const fn is_outdated(&self) -> bool { | ||
matches!(self, Self::Past) | ||
} | ||
|
||
/// Returns if the batch is future. | ||
pub const fn is_future(&self) -> bool { | ||
matches!(self, Self::Future) | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
|
||
#[test] | ||
fn test_batch_validity() { | ||
assert!(BatchValidity::Accept.is_accept()); | ||
assert!(BatchValidity::Drop.is_drop()); | ||
assert!(BatchValidity::Past.is_outdated()); | ||
assert!(BatchValidity::Future.is_future()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters