delfi

Crates.iodelfi
lib.rsdelfi
version0.1.0
sourcesrc
created_at2022-12-04 13:11:31.562452
updated_at2023-01-26 21:26:52.472323
descriptionConveniently writing data to csv-files
homepage
repositoryhttps://github.com/skogseth/delfi
max_upload_size
id729595
size98,475
Herman Skogseth (skogseth)

documentation

README

Delfi

Rust crate for conveniently writing data to csv-files. The crate aims to be a minimal interface for saving data to csv such that this is not a considerable part of your program, preferably only taking up a few lines of code.

Usage

A basic use of delfi is shown below:

use delfi::Dataset;

let t = vec![0.0, 1.0, 2.0];
let x = vec![0.0, 2.0, 6.0];
let dataset = Dataset::columns([t, x], ["time", "length"]);
dataset.save("./path/to/file.csv").unwrap();

Alternatively you can use the macro for slightly longer, but perhaps more readable, code:

use delfi::dataset;

let t = vec![0.0, 1.0, 2.0];
let x = vec![0.0, 2.0, 6.0];
let dataset = dataset!{
    "time" => t,
    "length" => x,
};
dataset.save("./path/to/file.csv").unwrap();

It works with anything iterable, so long as they are the same type. Here is an example using ndarray:

use delfi::dataset;
use ndarray::Array;

const N: usize = 1000;
let t = Array::linspace(0., 10., N+1);
let x = Array::logspace(10., 0., 2., N+1);

let dataset = dataset!{
    "time" => t,
    "length" => x,
};

dataset.save("./path/to/file.csv").unwrap();

Feature: macros

Work is currently being done to allow custom datastructures which combine multiple types. The current state allows patterns such as this (named structs are also supported):

use delfi::{Datapoint, Dataset};

#[derive(Datapoint)]
struct MyDatapoint(String, usize, f64);

let dp1 = MyDatapoint("Hello".to_owned(), 4, 10.2);
let dp2 = MyDatapoint("World".to_owned(), 5, 3.14);
let dataset = Dataset::from_datapoints([dp1, dp2]);

dataset.save("./path/to/file.csv").unwrap();

Hopefully this will be expanded upon in the future to allow for more ergonomic constructors.

Commit count: 17

cargo fmt