pub struct EventBuffer<'a> { /* private fields */ }Expand description
Caller-owned, pre-allocated event sink for one or more commands.
The buffer borrows a Vec<ExecutionEvent> the caller has already
reserved capacity on. The engine checks the remaining capacity in
preflight against the command’s worst-case event count and returns
crate::BookError::EventBufferFull before mutating anything when
it does not fit, so a push inside the engine can never grow the
vector. Events written by one command are the tail slice reported by
EventBuffer::written.
Implementations§
Source§impl<'a> EventBuffer<'a>
impl<'a> EventBuffer<'a>
Sourcepub const fn new(out: &'a mut Vec<ExecutionEvent>) -> Self
pub const fn new(out: &'a mut Vec<ExecutionEvent>) -> Self
Wrap a caller vector. Events already in the vector are left alone; capacity beyond its current length is the space commands may use.
Sourcepub const fn remaining(&self) -> usize
pub const fn remaining(&self) -> usize
Free event slots: reserved capacity minus current length.
Sourcepub fn written(&self) -> &[ExecutionEvent]
pub fn written(&self) -> &[ExecutionEvent]
Events written since this buffer was created (or last cleared).
Sourcepub fn clear(&mut self)
pub fn clear(&mut self)
Discard every event written through this buffer since it was created, reclaiming their capacity for subsequent commands while leaving any earlier entries in the underlying vector untouched.
§Examples
use chronicle_core::{
Book, BookConfig, EventBuffer, ExecutionEvent, OrderId, OrderType, ParticipantId,
Side, StpPolicy,
};
let mut book = Book::new(BookConfig {
max_orders: 16,
grid_len: 64,
tick_size: 1,
grid_start_tick: 1,
default_stp: StpPolicy::CancelIncoming,
})
.unwrap();
let mut storage: Vec<ExecutionEvent> = Vec::with_capacity(8);
let mut events = EventBuffer::new(&mut storage);
book.add_order(
OrderId(1),
ParticipantId(1),
Side::Bid,
OrderType::Limit,
10,
5,
None,
&mut events,
)
.unwrap();
assert_eq!(events.written().len(), 1);
events.clear();
assert!(events.written().is_empty());
assert_eq!(events.remaining(), 8);