re_types/lib.rs
1//! The standard Rerun data types, component types, and archetypes.
2//!
3//! This crate contains both the IDL definitions for Rerun types (flatbuffers) as well as the code
4//! generated from those using `re_types_builder`.
5//!
6//! All builtin archetypes, components, datatypes and view definitions can be found in their
7//! respective top-level modules.
8//!
9//! ## Contributing
10//!
11//! ### Organization
12//!
13//! - `definitions/` contains IDL definitions for all Rerun types (data, components, archetypes).
14//! - `src/` contains the code generated for Rust.
15//! - `rerun_py/rerun/rerun2/` (at the root of this workspace) contains the code generated for Python.
16//!
17//! While most of the code in this crate is auto-generated, some manual extensions are littered
18//! throughout: look for files ending in `_ext.rs`, `_ext.py`, or `_ext.cpp` (also see the "Extensions"
19//! section of this document).
20//!
21//!
22//! ### Build cache
23//!
24//! Updating either the source code of the code generator itself (`re_types_builder`) or any of the
25//! .fbs files should re-trigger the code generation process the next time `re_types` is built.
26//! Manual extension files will be left untouched.
27//!
28//! Caching is controlled by a versioning hash that is stored in `store_hash.txt`.
29//! If you suspect something is wrong with the caching mechanism and that your changes aren't taken
30//! into account when they should, try and remove `source_hash.txt`.
31//! If that fixes the issue, you've found a bug.
32//!
33//!
34//! ### How-to: add a new datatype/component/archetype
35//!
36//! Create the appropriate .fbs file in the appropriate place, and make sure it gets included in
37//! some way (most likely indirectly) by `archetypes.fbs`, which is the main entrypoint for
38//! codegen.
39//! Generally, the easiest thing to do is to add your new type to one of the centralized manifests,
40//! e.g. for a new component, include it into `components.fbs`.
41//!
42//! Your file should get picked up automatically by the code generator.
43//! Once the code for your new component has been generated, implement whatever extensions you need
44//! and make sure to tests any custom constructors you add.
45//!
46//!
47//! ### How-to: remove an existing datatype/component/archetype
48//!
49//! Simply get rid of the type in question and rebuild `re_types` to trigger codegen.
50//!
51//! Beware though: if you remove a whole definition file re-running codegen will not remove the
52//! associated generated files, you'll have to do that yourself.
53//!
54//!
55//! ### Extensions
56//!
57//!
58//! #### Rust
59//!
60//! Generated Rust code can be manually extended by adding sibling files with the `_ext.rs`
61//! prefix. E.g. to extend `vec2d.rs`, create a `vec2d_ext.rs`.
62//!
63//! Trigger the codegen (e.g. by removing `source_hash.txt`) to generate the right `mod` clauses
64//! automatically.
65//!
66//! The simplest way to get started is to look at any of the existing examples.
67//!
68//!
69//! #### Python
70//!
71//! Generated Python code can be manually extended by adding a sibling file with the `_ext.py`
72//! prefix. E.g. to extend `vec2d.py`, create a `vec2d_ext.py`.
73//!
74//! This sibling file needs to implement an extension class that is mixed in with the
75//! auto-generated class.
76//! The simplest way to get started is to look at any of the existing examples.
77//!
78//!
79//! #### C++
80//!
81//! Generated C++ code can be manually extended by adding a sibling file with the `_ext.cpp` suffix.
82//! E.g. to extend `vec2d.cpp`, create a `vec2d_ext.cpp`.
83//!
84//! The sibling file is compiled as-is as part of the `rerun_cpp` crate.
85//!
86//! Any include directive used in the extension is automatically added to the generated header,
87//! except to the generated header itself.
88//!
89//! In order to extend the generated type declaration in the header,
90//! you can specify a single code-block that you want to be injected into the type declaration by
91//! starting it with `<CODEGEN_COPY_TO_HEADER>` and ending it with `</CODEGEN_COPY_TO_HEADER>`.
92//! Note that it is your responsibility to make sure that the cpp file is valid C++ code -
93//! the code generator & build will not adjust the extension file for you!
94//!
95//! ### Language-specific documentation
96//!
97//! You can prefix any doc comment line with `\{tag}`, where `{tag}` is one of `py`, `cpp`, `rs`,
98//! and that part of the docs will only be present in the files generated for that specific
99//! language.
100//!
101//! ### Examples
102//!
103//! You can add an example to `docs/snippets/all`, and then include its source code in
104//! the docs using the `\example` tag. The example will also be included in the list of
105//! examples for type's generated docs.
106//!
107//! The `\example` tag supports the following arguments:
108//! - `title`: a short description of the example which will be shown before the source code
109//! - `image`: a link to an image, with special handling for images uploaded
110//! using `scripts/upload_image.py` to `static.rerun.io`
111//! - `!api`: if present, the example will *not* be included in comments embedded in the generated code
112//!
113//! ```text,ignore
114//! \example example_file_name title="Some title" image="https://link.to/any_image.png"
115//! ```
116//!
117//! If the url does not start with `https://static.rerun.io/`, then it will be used as the
118//! `src` attribute in an `img` HTML tag, without any changes:
119//! ```html,ignore
120//! <img src="https://link.to/any_image.png">
121//! ```
122//!
123//! Otherwise the URL is treated as a rerun screenshot, which expects the following link format:
124//! ```text,ignore
125//! https://static.rerun.io/{name}/{hash}/{max_width}.{ext}
126//! ```
127//!
128//! These parameters will be used to generate an image stack:
129//! - `name`: the original filename of the uploaded screenshot, without its extension
130//! - `hash`: the content hash of the original screenshot
131//! - `max_width`: the maximum width available for this screenshot.
132//! - If the value is not a valid integer suffixed by `w` (e.g. `1200w`), then the image stack will only include the `full` size.
133//! - If the value _is_ a valid integer, then sizes _larger_ than the value will be omitted from the stack.
134//! - `ext`: the file extension of the image (`png`, `jpeg`, etc.)
135//!
136//! Given a URL like `https://static.rerun.io/my_screenshot/9066060e59ee9d2d7d98b214b8db0b8f2e8ab4b8/1024w.png`,
137//! the docs codegen will generate the following image stack:
138//! ```html,ignore
139//! <picture>
140//! <source media="(max-width: 480px)" srcset="https://static.rerun.io/my_screenshot/9066060e59ee9d2d7d98b214b8db0b8f2e8ab4b8/480w.png">
141//! <source media="(max-width: 768px)" srcset="https://static.rerun.io/my_screenshot/9066060e59ee9d2d7d98b214b8db0b8f2e8ab4b8/768w.png">
142//! <source media="(max-width: 1024px)" srcset="https://static.rerun.io/my_screenshot/9066060e59ee9d2d7d98b214b8db0b8f2e8ab4b8/1024w.png">
143//! <img src="https://static.rerun.io/my_screenshot/9066060e59ee9d2d7d98b214b8db0b8f2e8ab4b8/full.png" alt="screenshot of {title} example">
144//! </picture>
145//! ```
146//! The `1200px` size was omitted from the stack.
147//!
148//! #### How to use this with `scripts/upload_image.py`
149//!
150//! Running `scripts/upload_image.py {file}` will generate an image stack.
151//! You need to take the _maximum width_ available in that stack, and use it as the value of `image=` in `\example`.
152//!
153//! For example, if the image stack generated by the script is:
154//! ```html,ignore
155//! <picture>
156//! <source media="(max-width: 480px)" srcset="https://static.rerun.io/my_screenshot/9066060e59ee9d2d7d98b214b8db0b8f2e8ab4b8/480w.png">
157//! <source media="(max-width: 768px)" srcset="https://static.rerun.io/my_screenshot/9066060e59ee9d2d7d98b214b8db0b8f2e8ab4b8/768w.png">
158//! <source media="(max-width: 1024px)" srcset="https://static.rerun.io/my_screenshot/9066060e59ee9d2d7d98b214b8db0b8f2e8ab4b8/1024w.png">
159//! <img src="https://static.rerun.io/my_screenshot/9066060e59ee9d2d7d98b214b8db0b8f2e8ab4b8/full.png">
160//! </picture>
161//! ```
162//! Then the url you should use is `https://static.rerun.io/my_screenshot/9066060e59ee9d2d7d98b214b8db0b8f2e8ab4b8/1024w.png`.
163//!
164//! It works this way because `upload_image.py` does not upscale screenshots, it only downscales them.
165//! We need to know what the maximum width we can use is, because we can't just provide all the widths all the time.
166//! If the currently-used `max-width` source fails to load, it will show the blank image icon.
167//! There is no way to provide a fallback in `<picture>` if a specific `max-width` source fails to load.
168//! Browsers will not automatically try to load the other sources!
169//!
170//! ## Feature flags
171#![doc = document_features::document_features!()]
172//!
173
174#![warn(missing_docs)] // Let's keep the this crate well-documented!
175
176// ---
177
178/// Number of decimals shown for all float display methods.
179pub use re_types_core::DEFAULT_DISPLAY_DECIMALS;
180
181/// Archetype are the high-level things you can log, like [`Image`][archetypes::Image], [`Points3D`][archetypes::Points3D], etc.
182///
183/// All archetypes implement the [`Archetype`] trait.
184///
185/// Each archetype is a collection of homogeneous [`ComponentBatch`]es.
186/// For instance, the [`Points3D`][archetypes::Points3D] archetype contains a
187/// batch of positions, a batch of colors, etc.
188///
189/// Each entity can consist of many archetypes, but usually each entity will only have one archetype.
190///
191/// A special archetype is [`Clear`][archetypes::Clear] which resets all the components
192/// of an already logged entity.
193pub mod archetypes {
194
195 // Some archetypes (e.g. `Clear`) are so fundamental and used everywhere that we want
196 // them to be exposed by `re_types_core` directly; that way we don't force a dependency on the
197 // `re_types` behemoth just so one can use one of these fundamental types.
198 //
199 // To do so, re-inject `re_types_core`'s archetypes into our own module.
200
201 #[path = "../archetypes/mod.rs"]
202 mod _archetypes;
203
204 pub use self::_archetypes::*;
205 pub use re_types_core::archetypes::*;
206}
207
208/// Components are the basic building blocks of [`archetypes`].
209///
210/// They all implement the [`Component`] trait.
211///
212/// Each component is a wrapper around a [`datatype`][datatypes].
213pub mod components {
214
215 // Some components are so fundamental and used everywhere that we want them to be exposed
216 // by `re_types_core` directly; that way we don't force a dependency on the `re_types`
217 // behemoth just so one can use one of these fundamental types.
218 //
219 // To do so, re-inject `re_types_core`'s components into our own module.
220
221 #[path = "../components/mod.rs"]
222 mod _components;
223
224 pub use self::_components::*;
225 pub use re_types_core::components::*;
226}
227
228/// The low-level datatypes that [`components`] are built from.
229///
230/// They all implement the [`Loggable`] trait.
231pub mod datatypes {
232
233 // Some datatypes are so fundamental and used everywhere that we want them to be exposed
234 // by `re_types_core` directly; that way we don't force a dependency on the `re_types`
235 // behemoth just so one can use one of these fundamental types.
236 //
237 // To do so, re-inject `re_types_core`'s datatypes into our own module.
238
239 #[path = "../datatypes/mod.rs"]
240 mod _datatypes;
241
242 pub use self::_datatypes::*;
243 pub use re_types_core::datatypes::*;
244}
245
246/// The blueprint-specific components.
247pub mod blueprint;
248
249/// Run-time reflection for reading meta-data about components and archetypes.
250pub mod reflection {
251
252 // Some reflection types are so fundamental and used everywhere that we want them to be
253 // exposed by `re_types_core` directly; that way we don't force a dependency on the `re_types`
254 // behemoth just so one can use one of these fundamental reflection types.
255 //
256 // To do so, re-inject `re_types_core`'s datatypes into our own module.
257
258 #[path = "../reflection/mod.rs"]
259 mod _reflection;
260
261 pub use self::_reflection::*;
262 pub use re_types_core::reflection::*;
263}
264
265// ---
266
267// One almost never uses `re_types` without `re_types_core`, so we reexport these core types
268// for convenience.
269// The opposite is not true, though: make sure you're not depending on `re_types` if all you need
270// in `re_types_core` in order to prevent some nasty dep cycles!
271pub use re_types_core::*;
272
273// ---
274
275/// Re-exports of external crates that are used throughout the codebase.
276pub mod external {
277 pub use re_types_core;
278
279 pub use anyhow;
280 pub use arrow;
281 pub use ndarray;
282 pub use uuid;
283
284 #[cfg(feature = "ecolor")]
285 pub use ecolor;
286
287 #[cfg(feature = "glam")]
288 pub use glam;
289
290 #[cfg(feature = "image")]
291 pub use image;
292}
293
294// TODO(jleibs): Should all of this go into `tensor_data_ext`? Don't have a good way to export
295// additional helpers yet.
296pub mod image;
297pub mod tensor_data;
298pub mod view_coordinates;
299
300pub mod any_values;
301pub use any_values::AnyValues;
302
303mod rotation3d;
304pub use rotation3d::Rotation3D;
305
306#[cfg(feature = "testing")]
307pub mod testing;