Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Rust snippets for columnar updates of custom data #8778

Open
wants to merge 12 commits into
base: cmc/unit_columns
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions crates/build/re_types_builder/src/codegen/docs/snippets_ref.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,11 @@ impl SnippetsRefCodeGenerator {
String::new()
};

// NOTE: `/` is written with a UTF8 zero-width word joiner (<https://unicode-explorer.com/c/2060>)
// on both sides in order to force the markdown renderer to *not* split it into two lines ("archetype/\nthing").
#[allow(clippy::invisible_characters)]
let snippet_name_qualified = &snippet.name_qualified.replace('/', "⁠/⁠");

let row = format!("| **{obj_name_rendered}** | `{snippet_name_qualified}` | {snippet_descr} | {link_py} | {link_rs} | {link_cpp} |");

Ok(row)
Expand Down Expand Up @@ -333,6 +338,9 @@ impl SnippetsRefCodeGenerator {
"<!-- DO NOT EDIT! This file was auto-generated by {} -->",
file!().replace('\\', "/")
);
// NOTE: `C++` is written with a UTF8 zero-width word joiner (<https://unicode-explorer.com/c/2060>) in
// order to force the markdown renderer to *not* split it into two lines ("C+\n+").
#[allow(clippy::invisible_characters)]
let out = format!(
"
{autogen_warning}
Expand All @@ -357,7 +365,7 @@ Use it to quickly find copy-pastable snippets of code for any Rerun feature you'

## Features

| Feature | Example | Description | Python | Rust | C++ |
| Feature | Example | Description | Python | Rust | C++ |
| ------- | ------- | ----------- | ------ | ---- | --- |
{per_feature_table}

Expand All @@ -370,7 +378,7 @@ Use it to quickly find copy-pastable snippets of code for any Rerun feature you'

_All snippets, organized by the [`Archetype`](https://rerun.io/docs/reference/types/archetypes)(s) they use._

| Archetype | Snippet | Description | Python | Rust | C++ |
| Archetype | Snippet | Description | Python | Rust | C++ |
| --------- | ------- | ----------- | ------ | ---- | --- |
{per_archetype_table}

Expand All @@ -379,7 +387,7 @@ _All snippets, organized by the [`Archetype`](https://rerun.io/docs/reference/ty

_All snippets, organized by the [`Component`](https://rerun.io/docs/reference/types/components)(s) they use._

| Component | Snippet | Description | Python | Rust | C++ |
| Component | Snippet | Description | Python | Rust | C++ |
| --------- | ------- | ----------- | ------ | ---- | --- |
{per_component_table}

Expand All @@ -388,7 +396,7 @@ _All snippets, organized by the [`Component`](https://rerun.io/docs/reference/ty

_All snippets, organized by the [`View`](https://rerun.io/docs/reference/types/views)(s) they use._

| Component | Snippet | Description | Python | Rust | C++ |
| Component | Snippet | Description | Python | Rust | C++ |
| --------- | ------- | ----------- | ------ | ---- | --- |
{per_view_table}

Expand All @@ -397,7 +405,7 @@ _All snippets, organized by the [`View`](https://rerun.io/docs/reference/types/v

_All snippets, organized by the blueprint-related [`Archetype`](https://rerun.io/docs/reference/types/archetypes)(s) they use._

| Archetype | Snippet | Description | Python | Rust | C++ |
| Archetype | Snippet | Description | Python | Rust | C++ |
| --------- | ------- | ----------- | ------ | ---- | --- |
{per_archetype_blueprint_table}

Expand All @@ -406,7 +414,7 @@ _All snippets, organized by the blueprint-related [`Archetype`](https://rerun.io

_All snippets, organized by the blueprint-related [`Component`](https://rerun.io/docs/reference/types/components)(s) they use._

| Component | Snippet | Description | Python | Rust | C++ |
| Component | Snippet | Description | Python | Rust | C++ |
| --------- | ------- | ----------- | ------ | ---- | --- |
{per_component_blueprint_table}
"
Expand Down
636 changes: 322 additions & 314 deletions docs/snippets/INDEX.md

Large diffs are not rendered by default.

41 changes: 41 additions & 0 deletions docs/snippets/all/howto/any_batch_value_send_columns.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
//! Use `send_column` to send an entire column of custom data to Rerun.

#![allow(clippy::from_iter_instead_of_collect)]

use std::sync::Arc;

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

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

const STEPS: i64 = 64;

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

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

let ten_per_timestamp = rerun::SerializedComponentBatch::new(
Arc::new(arrow::array::Float64Array::from_iter((0..STEPS).flat_map(
|_| (0..STEPS * 10).map(|v| ((v as f64) / 100.0).cos()),
))),
rerun::ComponentDescriptor::new("custom_component_multi"),
);

rec.send_columns_v2(
"/",
[times],
[
one_per_timestamp.partitioned(std::iter::repeat(1).take(STEPS as _))?,
ten_per_timestamp.partitioned(std::iter::repeat(10).take(STEPS as _))?,
],
)?;

Ok(())
}
41 changes: 41 additions & 0 deletions docs/snippets/all/howto/any_values_send_columns.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
//! Use `send_column` to send entire columns of custom data to Rerun.

#![allow(clippy::from_iter_instead_of_collect)]

use std::sync::Arc;

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

fn main() -> Result<(), Box<dyn std::error::Error>> {
let rec =
rerun::RecordingStreamBuilder::new("rerun_example_any_values_send_columns").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_v2(
"/",
[times],
[
sin.partitioned(std::iter::repeat(1).take(STEPS as _))?,
cos.partitioned(std::iter::repeat(1).take(STEPS as _))?,
],
)?;

Ok(())
}
1 change: 0 additions & 1 deletion docs/snippets/all/tutorials/custom_data.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#!/usr/bin/env python3
"""Shows how to implement custom archetypes and components."""

from __future__ import annotations
Expand Down
25 changes: 20 additions & 5 deletions docs/snippets/snippets.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,29 @@

# These arbitrary feature names will be indexed exactly as written down.
# Add anything you can think about!
#
# Tip: use UTF8 NBSPs (https://unicode-explorer.com/c/00A0) as needed.
[snippets_ref.features]
"Dataframes" = ["reference/dataframe_query", "reference/dataframe_view_query"]
"`AnyValue`" = [
"Query dataframes" = [
"reference/dataframe_query",
"reference/dataframe_view_query",
]
"Send partial updates" = [
"archetypes/mesh3d_partial_updates",
"archetypes/points3d_partial_updates",
"archetypes/transform3d_partial_updates",
]
"Send columnar data" = [
"archetypes/image_send_columns",
"archetypes/points3d_send_columns",
"archetypes/scalar_send_columns",
"howto/any_values_send_columns",
"howto/any_batch_value_send_columns",
]
"Send custom data" = [
"tutorials/any_values",
"tutorials/extra_values",
"howto/any_values_send_columns",
"tutorials/custom_data",
]

# These entries won't run at all.
Expand Down Expand Up @@ -86,11 +103,9 @@
]
"howto/any_batch_value_send_columns" = [
"cpp", # Not implemented
"rust", # Not implemented
]
"howto/any_values_send_columns" = [
"cpp", # Not implemented
"rust", # Not implemented
]
"migration/log_line" = [ # Not a complete example -- just a single log line
"cpp",
Expand Down
2 changes: 2 additions & 0 deletions lychee.toml
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,8 @@ exclude = [
'https://github.com/rerun-io/rerun/blob/main/docs/snippets/all/archetypes/transform3d_partial_updates.cpp',
'https://github.com/rerun-io/rerun/blob/main/docs/snippets/all/archetypes/transform3d_partial_updates.py',
'https://github.com/rerun-io/rerun/blob/main/docs/snippets/all/archetypes/transform3d_partial_updates.rs',
'https://github.com/rerun-io/rerun/blob/main/docs/snippets/all/howto/any_batch_value_send_columns.rs',
'https://github.com/rerun-io/rerun/blob/main/docs/snippets/all/howto/any_values_send_columns.rs',
'https://github.com/rerun-io/rerun/blob/main/docs/snippets/all/tutorials/any_values.rs',
'https://github.com/rerun-io/rerun/blob/main/docs/snippets/all/tutorials/extra_values.rs',
]
Loading