[−][src]Derive Macro timescale_macros::InterpolatedDataTable
#[derive(InterpolatedDataTable)] { // Attributes available to this derive: #[table] }
Load a csv file into a static data table with support for linearly interpolating data points between the discreet time intervals
This derive macro goes hand and hand with the InterpolatedData
derive
macro. Data loaded into this table needs to be decorated with the aforementioned
InterpolatedData
derive macro so that their structure can be available to
this macro at build time.
Arguments
This macro requires 2 arguments.
st
describes the structure (that derivesInterpolatedData
) to represent the timescale data.file
describes the csv file to read in the timescale data from
Example
See the data in this csv file for context for the following example
use timescale::{InterpolatedData, InterpolatedDataTable}; #[derive(Debug, Lerp, InterpolatedData)] pub struct RocketEngine { #[data(rename = "Thrust (N)")] pub thrust: f64, } /// The thrust curve of an Estes A8 rocket motor #[derive(InterpolatedDataTable)] #[table(file = "../assets/motors/Estes_A8.csv", st = "RocketEngine")] pub struct EstesA8; fn main() { assert_eq!(EstesA8::get(0.35).thrust, 3.813); // Exact value from data assert_eq!(EstesA8::get(0.4).thrust, 3.9468823529411763); // Linear interpolated estimate assert_eq!(EstesA8::get(1.0).thrust, 0.0); // Saturated at 0 }