mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-05-29 19:49:28 -07:00
brk: first commit
This commit is contained in:
31
_src/structs/counter.rs
Normal file
31
_src/structs/counter.rs
Normal file
@@ -0,0 +1,31 @@
|
||||
use allocative::Allocative;
|
||||
use bincode::{Decode, Encode};
|
||||
use derive_deref::{Deref, DerefMut};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(
|
||||
Debug, Deref, DerefMut, Default, Clone, Copy, Encode, Decode, Serialize, Deserialize, Allocative,
|
||||
)]
|
||||
pub struct Counter(u32);
|
||||
|
||||
impl Counter {
|
||||
#[inline(always)]
|
||||
pub fn increment(&mut self) {
|
||||
self.0 += 1;
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn decrement(&mut self) {
|
||||
self.0 -= 1;
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn reset(&mut self) {
|
||||
self.0 = 0;
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn inner(&self) -> u32 {
|
||||
self.0
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user