snippets/snippets/
any_values_column_updates.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
//! DO NOT EDIT! This file was autogenerated by `docs/snippets/build.rs`. The original is in `/home/runner/work/rerun/rerun/docs/snippets/all/howto/any_values_column_updates.rs`.
//! Update custom user-defined values over time, in a single operation.
//!
//! This is semantically equivalent to the `any_values_row_updates` example, albeit much faster.

#![allow(clippy::from_iter_instead_of_collect)]

use std::sync::Arc;

use rerun::{external::arrow, TimeColumn};

pub fn main(_args: &[String]) -> Result<(), Box<dyn std::error::Error>> {
    let rec =
        rerun::RecordingStreamBuilder::new("rerun_example_any_values_column_updates").spawn()?;

    const STEPS: i64 = 64;

    let times = TimeColumn::new_sequence("step", 0..STEPS);

    let sin = rerun::SerializedComponentBatch::new(
        Arc::new(arrow::array::Float64Array::from_iter(
            (0..STEPS).map(|v| ((v as f64) / 10.0).sin()),
        )),
        rerun::ComponentDescriptor::new("sin"),
    );

    let cos = rerun::SerializedComponentBatch::new(
        Arc::new(arrow::array::Float64Array::from_iter(
            (0..STEPS).map(|v| ((v as f64) / 10.0).cos()),
        )),
        rerun::ComponentDescriptor::new("cos"),
    );

    rec.send_columns(
        "/",
        [times],
        [
            sin.partitioned(std::iter::repeat(1).take(STEPS as _))?,
            cos.partitioned(std::iter::repeat(1).take(STEPS as _))?,
        ],
    )?;

    Ok(())
}