Skip to main content

Series

Struct Series 

Source
pub struct Series<T> { /* private fields */ }
Expand description

A bounded, time-ordered ring buffer of samples.

Appending is O(1), the oldest samples drop off once capacity is reached, and range lookups are binary searches. A push with the same time as the newest sample replaces it, which is how a live candle or price updates in place.

Implementations§

Source§

impl<T: Sample> Series<T>

Source

pub fn with_capacity(capacity: usize) -> Series<T>

An empty series holding at most capacity samples (at least one).

Source

pub fn capacity(&self) -> usize

The maximum number of samples kept.

Source

pub fn set_capacity(&mut self, capacity: usize)

Changes the capacity, dropping the oldest samples if needed.

Source

pub fn len(&self) -> usize

The number of samples.

Source

pub fn is_empty(&self) -> bool

Whether there are no samples.

Source

pub fn revision(&self) -> u64

Bumped on every change; compare it to skip work when nothing changed.

Source

pub fn push(&mut self, sample: T) -> Result<Change, OutOfOrder>

Appends sample, or replaces the newest one if it has the same time.

Source

pub fn extend<I: IntoIterator<Item = T>>( &mut self, samples: I, ) -> Result<(), OutOfOrder>

Pushes every sample in order, stopping at the first out-of-order one.

Source

pub fn replace_all(&mut self, samples: Vec<T>)

Replaces the contents with samples, which are sorted by time first (history loads). Later duplicates of a time win.

Source

pub fn update_last(&mut self, f: impl FnOnce(&mut T)) -> bool

Edits the newest sample in place (its time must not change).

Source

pub fn clear(&mut self)

Removes every sample.

Source

pub fn first(&self) -> Option<&T>

The oldest sample.

Source

pub fn last(&self) -> Option<&T>

The newest sample.

Source

pub fn iter(&self) -> impl DoubleEndedIterator<Item = &T> + ExactSizeIterator

Every sample, oldest first.

Source

pub fn get(&self, index: usize) -> Option<&T>

The sample at index (0 is the oldest).

Source

pub fn index_range(&self, start: Timestamp, end: Timestamp) -> Range<usize> ⓘ

The index range of samples with start <= time <= end.

Source

pub fn range( &self, start: Timestamp, end: Timestamp, ) -> impl DoubleEndedIterator<Item = &T> + ExactSizeIterator

Samples with start <= time <= end, oldest first.

Source

pub fn range_padded( &self, start: Timestamp, end: Timestamp, ) -> impl DoubleEndedIterator<Item = &T> + ExactSizeIterator

Like range plus one sample on each side when there is one, so lines run to the edges of a viewport.

Source

pub fn extent(&self, start: Timestamp, end: Timestamp) -> Option<(f64, f64)>

The lowest and highest value among samples in [start, end], ignoring non-finite values.

Source

pub fn interval(&self) -> Option<i64>

The typical spacing between samples: the median of the last (up to) 64 gaps.

Source§

impl Series<Candle>

Source

pub fn apply_trade( &mut self, time: Timestamp, price: f64, size: f64, interval_ms: i64, ) -> Result<Change, OutOfOrder>

Folds a trade into the candle for interval_ms-long bars starting at multiples of the interval: it updates the open candle or starts the next one.

Trait Implementations§

Source§

impl<T: Clone> Clone for Series<T>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: Debug> Debug for Series<T>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<T> Forget for Series<T>

§

impl<T> Freeze for Series<T>
where VecDeque<T>: Freeze,

§

impl<T> Move for Series<T>

§

impl<T> RefUnwindSafe for Series<T>

§

impl<T> Send for Series<T>
where VecDeque<T>: Send,

§

impl<T> Sync for Series<T>
where VecDeque<T>: Sync,

§

impl<T> Unpin for Series<T>
where VecDeque<T>: Unpin,

§

impl<T> UnsafeUnpin for Series<T>

§

impl<T> UnwindSafe for Series<T>
where VecDeque<T>: 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.