Skip to main content

EventBuffer

Struct EventBuffer 

Source
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>

Source

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.

Source

pub const fn remaining(&self) -> usize

Free event slots: reserved capacity minus current length.

Source

pub fn written(&self) -> &[ExecutionEvent]

Events written since this buffer was created (or last cleared).

Source

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);

Auto Trait Implementations§

§

impl<'a> !UnwindSafe for EventBuffer<'a>

§

impl<'a> Forget for EventBuffer<'a>

§

impl<'a> Freeze for EventBuffer<'a>

§

impl<'a> Move for EventBuffer<'a>

§

impl<'a> RefUnwindSafe for EventBuffer<'a>

§

impl<'a> Send for EventBuffer<'a>

§

impl<'a> Sync for EventBuffer<'a>

§

impl<'a> Unpin for EventBuffer<'a>

§

impl<'a> UnsafeUnpin for EventBuffer<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.