Skip to main content

FinishedWindow

Struct FinishedWindow 

Source
pub struct FinishedWindow<K> { /* private fields */ }
Expand description

A memory window for things that belong to finished orders: the cid maps of a connector.

A connector keeps small maps next to its OrderRuntime (cid to instrument, broker id to cid, …). When an order is final, the connector pushes its cid here. Whatever is older than the window, or beyond the count limit, comes back from expired, and the connector drops the entries of those cids. So the maps stay as big as a day of trading and not as the whole life of the process.

§Examples

use std::time::{Duration, Instant};
use brokapi_runtime::FinishedWindow;

let mut window = FinishedWindow::with_limits(Duration::from_secs(60), 100);
let t0 = Instant::now();
window.push(t0, "a");
window.push(t0 + Duration::from_secs(30), "b");
assert!(window.expired(t0 + Duration::from_secs(59)).is_empty());
assert_eq!(window.expired(t0 + Duration::from_secs(61)), vec!["a"]);
assert_eq!(window.len(), 1);

Implementations§

Source§

impl<K> FinishedWindow<K>

Source

pub fn new() -> Self

A window of RETENTION and RETAINED_FINISHED.

Source

pub fn with_limits(window: Duration, max: usize) -> Self

A window that keeps a key for window, and at most max keys.

Source

pub fn push(&mut self, now: Instant, key: K)

Notes that the order key finished at now.

Source

pub fn expired(&mut self, now: Instant) -> Vec<K>

Takes out the keys that are older than the window as of now, or beyond the count limit, oldest first. The caller drops what it kept for them.

Source

pub fn len(&self) -> usize

How many keys are held.

Source

pub fn is_empty(&self) -> bool

true when no key is held.

Trait Implementations§

Source§

impl<K: Debug> Debug for FinishedWindow<K>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<K> Default for FinishedWindow<K>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<K> Freeze for FinishedWindow<K>

§

impl<K> RefUnwindSafe for FinishedWindow<K>
where K: RefUnwindSafe,

§

impl<K> Send for FinishedWindow<K>
where K: Send,

§

impl<K> Sync for FinishedWindow<K>
where K: Sync,

§

impl<K> Unpin for FinishedWindow<K>
where K: Unpin,

§

impl<K> UnsafeUnpin for FinishedWindow<K>

§

impl<K> UnwindSafe for FinishedWindow<K>
where K: UnwindSafe,

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.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more