rerun/
lib.rs

1//! # Rerun - Visualize streams of multimodal data.
2//!
3//! Add the `rerun` library to your crate with `cargo add rerun`.
4//!
5//! There is also a `rerun` binary.
6//! The binary is required in order to stream log data
7//! over the networks, and to open our `.rrd` data files.
8//! If you need it, install the `rerun` binary with `cargo install rerun-cli --locked`.
9//!
10//!
11//! ## Feature flags
12#![doc = document_features::document_features!()]
13//!
14//!
15//! ## Links
16//! - [Examples](https://github.com/rerun-io/rerun/tree/latest/examples/rust)
17//! - [High-level docs](http://rerun.io/docs)
18//! - [Rust API docs](https://docs.rs/rerun/)
19//! - [Troubleshooting](https://www.rerun.io/docs/getting-started/troubleshooting)
20//!
21//! There are many different ways of sending data to the Rerun Viewer depending on what you're
22//! trying to achieve and whether the viewer is running in the same process as your code, in
23//! another process, or even as a separate web application.
24//!
25//! Checkout [SDK Operating Modes](https://www.rerun.io/docs/reference/sdk/operating-modes) for an
26//! overview of what's possible and how.
27//!
28//! If you get stuck on anything, open an issue at <https://github.com/rerun-io/rerun/issues>.
29//! You can also ask questions on the [Rerun Discord](https://discord.gg/Gcm8BbTaAj).
30//!
31//!
32//! ## Using the `rerun` binary
33//! The `rerun` binary is required in order to stream log data
34//! over the networks, and to open our `.rrd` data files.
35//!
36//! The binary can act either as a server, a viewer, or both,
37//! depending on which options you use when you start it.
38//!
39//! Install it with `cargo install rerun-cli --locked`.
40//!
41//! Running just `rerun` will start the viewer, waiting for the logging library to connect
42//! using [`RecordingStreamBuilder::connect_grpc`] (see below).
43//!
44//! You can run `rerun --help` for more info.
45//!
46//!
47//! ## Using the `rerun` library
48//! #### Logging
49//! You first create a [`RecordingStream`] using [`RecordingStreamBuilder`].
50//! You then use it to log some [`archetypes`] to a given [`EntityPath`] using [`RecordingStream::log`]:
51//!
52//! ```no_run
53//! # use rerun::external::image;
54//! # fn capture_image() -> image::DynamicImage { Default::default() }
55//! # fn positions() -> Vec<rerun::Position3D> { Default::default() }
56//! # fn colors() -> Vec<rerun::Color> { Default::default() }
57//! // Stream log data to an awaiting `rerun` process.
58//! let rec = rerun::RecordingStreamBuilder::new("rerun_example_app").connect_grpc()?;
59//!
60//! let points: Vec<rerun::Position3D> = positions();
61//! let colors: Vec<rerun::Color> = colors();
62//! let image: image::DynamicImage = capture_image();
63//!
64//! rec.set_time_sequence("frame", 42);
65//! rec.log("path/to/points", &rerun::Points3D::new(points).with_colors(colors))?;
66//! rec.log("path/to/image", &rerun::Image::from_color_model_and_tensor(rerun::ColorModel::RGB, image)?)?;
67//!
68//! # Ok::<(), Box<dyn std::error::Error>>(())
69//! ```
70//!
71//! #### Streaming to disk
72//! Streaming data to a file on disk using the `.rrd` format:
73//!
74//! ```no_run
75//! let rec = rerun::RecordingStreamBuilder::new("rerun_example_app").save("my_data.rrd")?;
76//!
77//! # Ok::<(), Box<dyn std::error::Error>>(())
78//! ```
79//!
80//! #### Buffering
81//! You can buffer the log messages in memory and then show them in an embedded viewer:
82//!
83//! ```no_run
84//! # let main_thread_token = re_capabilities::MainThreadToken::i_promise_i_am_on_the_main_thread();
85//! # fn log_to(rec: &rerun::RecordingStream) {}
86//! let (rec, storage) = rerun::RecordingStreamBuilder::new("rerun_example_app").memory()?;
87//! log_to(&rec);
88//!
89//! // Will block program execution!
90//! rerun::native_viewer::show(main_thread_token, storage.take());
91//!
92//! # Ok::<(), Box<dyn std::error::Error>>(())
93//! ```
94//!
95//! ```ignore
96//! cargo install rerun --locked
97//! rerun --help
98//! ```
99//!
100//!
101//! ## Forwarding text log events to Rerun
102//! See [`Logger`].
103//!
104
105#![warn(missing_docs)] // Let's keep the this crate well-documented!
106
107#[cfg(feature = "run")]
108mod commands;
109
110#[cfg(feature = "sdk")]
111mod sdk;
112
113#[cfg(all(feature = "clap", not(target_arch = "wasm32")))]
114pub mod clap;
115
116/// Methods for spawning the native viewer and streaming the SDK log stream to it.
117#[cfg(all(feature = "sdk", feature = "native_viewer"))]
118pub mod native_viewer;
119
120#[cfg(feature = "demo")]
121pub mod demo_util;
122
123#[cfg(feature = "log")]
124pub mod log_integration;
125
126#[cfg(feature = "log")]
127pub use re_log::default_log_filter;
128
129#[cfg(feature = "log")]
130pub use log_integration::Logger;
131
132#[cfg(feature = "run")]
133pub use commands::{CallSource, run};
134
135#[cfg(feature = "sdk")]
136pub use sdk::*;
137
138/// All the types required by the dataframe API.
139#[cfg(feature = "dataframe")]
140pub mod dataframe {
141    pub use re_dataframe::*;
142}
143
144/// Everything needed to build custom `ChunkStoreSubscriber`s.
145pub use re_entity_db::external::re_chunk_store::{
146    ChunkStore, ChunkStoreConfig, ChunkStoreDiff, ChunkStoreDiffKind, ChunkStoreEvent,
147    ChunkStoreGeneration, ChunkStoreHandle, ChunkStoreSubscriber,
148};
149pub use re_log_types::StoreKind;
150
151pub use re_capabilities::MainThreadToken;
152
153/// To register a new external data loader, simply add an executable in your $PATH whose name
154/// starts with this prefix.
155// NOTE: this constant is duplicated in `re_data_source` to avoid an extra dependency here.
156pub const EXTERNAL_DATA_LOADER_PREFIX: &str = "rerun-loader-";
157
158/// When an external `DataLoader` is asked to load some data that it doesn't know
159/// how to load, it should exit with this exit code.
160// NOTE: Always keep in sync with other languages.
161// NOTE: this constant is duplicated in `re_data_source` to avoid an extra dependency here.
162pub const EXTERNAL_DATA_LOADER_INCOMPATIBLE_EXIT_CODE: i32 = 66;
163
164/// Re-exports of other crates.
165pub mod external {
166    pub use anyhow;
167    pub use arrow;
168
169    pub use ::re_arrow_util;
170    pub use ::re_build_info;
171    pub use ::re_entity_db;
172    pub use ::re_entity_db::external::*;
173    pub use ::re_error;
174    pub use ::re_format;
175
176    #[cfg(feature = "run")]
177    pub use re_data_source;
178
179    #[cfg(feature = "clap")]
180    #[cfg(not(target_arch = "wasm32"))]
181    pub use clap;
182
183    #[cfg(any(feature = "run", feature = "native_viewer"))]
184    pub use re_crash_handler;
185
186    #[cfg(feature = "native_viewer")]
187    pub use re_viewer;
188
189    #[cfg(feature = "native_viewer")]
190    pub use re_viewer::external::*;
191
192    #[cfg(any(feature = "sdk", feature = "server"))]
193    pub use re_sdk::external::*;
194
195    #[cfg(feature = "sdk")]
196    pub use re_types;
197
198    #[cfg(feature = "sdk")]
199    pub use re_types::external::*;
200
201    #[cfg(feature = "oss_server")]
202    pub use ::re_server;
203}