mirror of
https://github.com/Cuprate/cuprate.git
synced 2025-01-27 04:45:57 +00:00
c840053854
* consensus: enable workspace lints * rules/fast-sync: enable workspace lints * typos * fixes * `PoW` -> proof-of-work
33 lines
755 B
Rust
33 lines
755 B
Rust
//! Tokens
|
|
//!
|
|
//! This module contains tokens which keep track of the validity of certain data.
|
|
//! Currently, there is 1 token:
|
|
//! - [`ValidityToken`]
|
|
//!
|
|
|
|
use tokio_util::sync::CancellationToken;
|
|
|
|
/// A token representing if a piece of data is valid.
|
|
#[derive(Debug, Clone, Default)]
|
|
pub struct ValidityToken {
|
|
token: CancellationToken,
|
|
}
|
|
|
|
impl ValidityToken {
|
|
/// Creates a new [`ValidityToken`]
|
|
pub fn new() -> Self {
|
|
Self {
|
|
token: CancellationToken::new(),
|
|
}
|
|
}
|
|
|
|
/// Returns `true` if the data is still valid.
|
|
pub fn is_data_valid(&self) -> bool {
|
|
!self.token.is_cancelled()
|
|
}
|
|
|
|
/// Sets the data to invalid.
|
|
pub fn set_data_invalid(self) {
|
|
self.token.cancel();
|
|
}
|
|
}
|