Rust (original) (raw)

Setup setup

The Rerun SDK for Rust requires a working installation of Rust 1.84+.

After you have installed the viewer you can simply add the Rerun crate to your project with cargo add rerun.

Let's try it out in a brand new Rust project:

$ cargo init cube && cd cube && cargo add rerun

Logging some data logging-some-data

Add the following code to your main.rs(This example also lives in the rerun source tree example)

use rerun::{demo_util::grid, external::glam};

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let rec = rerun::RecordingStreamBuilder::new("rerun_example_minimal").spawn()?;

    let points = grid(glam::Vec3::splat(-10.0), glam::Vec3::splat(10.0), 10);
    let colors = grid(glam::Vec3::ZERO, glam::Vec3::splat(255.0), 10)
        .map(|v| rerun::Color::from_rgb(v.x as u8, v.y as u8, v.z as u8));

    rec.log(
        "my_points",
        &rerun::Points3D::new(points)
            .with_colors(colors)
            .with_radii([0.5]),
    )?;

    Ok(())
}

Now run your application:

Once everything finishes compiling, you will see the points in the Rerun Viewer:

Using the Viewer using-the-viewer

Try out the following to interact with the viewer:

If you're facing any difficulties, don't hesitate to open an issue or join the Discord server.

What's next whats-next

If you're ready to move on to more advanced topics, check out the Viewer Walkthrough or our more advanced guide for Logging Data in Rust where we will explore the core concepts that make Rerun tick and log our first non-trivial dataset.

If you'd rather learn from examples, check out the example gallery for some more realistic examples, or browse the Types section for more simple examples of how to use the main datatypes.