Crate time_series_utils

Source
Expand description

This module provides a convenient way to handle time-series data in Rust. It allows the user to create and manipulate time-series data and perform arithmetic operations on them.

§Getting Started

import the module in your Rust code using:

use time_series::TimeSeries;

§Creating a new TimeSeries

To create a new TimeSeries, use the new() method:

let mut ts: TimeSeries<f64> = TimeSeries::new();

This creates a new TimeSeries that can hold floating-point numbers. You can add elements to the TimeSeries using the push() method:

ts.push(1.0);

§Arithmetic operations

The TimeSeries type defines arithmetic operations for types that implement the Add, Sub, Mul, and Div traits. The following operations are available:

  • TimeSeries<T> @ TimeSeries<T>
  • TimeSeries<T> @ &TimeSeries<T>
  • &TimeSeries<T> @ TimeSeries<T>
  • &TimeSeries<T> @ &TimeSeries<T> However, @ refers to the four arithmetic operations +, -, *, /. For example, to add two TimeSeries, use the + operator:
let ts1: TimeSeries<f64> = TimeSeries::new();
let ts2: TimeSeries<f64> = TimeSeries::new();
let ts3 = &ts1 + &ts2;
let ts4 = ts1 + ts2;

§Attention.

I don’t know why, but it seems that an error is detected by rust-analyzer regarding TimeSeries<T> @ TimeSeries<T>. It actually works, but may be a bit of a hindrance when coding.

§Mapping

You can apply a function to each element of a TimeSeries using the map() method. For example:

let mut ts:TimeSeries<f64> = TimeSeries::new();
ts.push(1.);
ts.push(2.);
ts.push(3.);
let ts2 = ts.map(|x| x * 2.0);
dbg!(ts2);

Structs§

TimeSeries

Traits§

Variation