Skip to main content

re_log_types/path/
mod.rs

1//! Every logged entity in Rerun is logged to an [`EntityPath`].
2//!
3//! The path is made up out of several [`EntityPathPart`]s,
4//! which are just non-empty strings.
5
6mod component_path;
7mod data_path;
8mod entity_path;
9mod entity_path_filter;
10mod entity_path_part;
11pub mod natural_ordering;
12mod parse_path;
13
14pub use component_path::ComponentPath;
15pub use data_path::DataPath;
16pub use entity_path::{EntityPath, EntityPathHash};
17pub use entity_path_filter::{
18    EntityPathFilter, EntityPathFilterError, EntityPathRule, EntityPathSubs, FilterEvaluation,
19    ResolvedEntityPathFilter, ResolvedEntityPathRule, RuleEffect,
20};
21pub use entity_path_part::EntityPathPart;
22pub use parse_path::{PathParseError, tokenize_by};
23
24// ----------------------------------------------------------------------------
25
26/// Reexports for use by macros to avoid depending on the caller's namespacing.
27#[doc(hidden)]
28pub mod __private {
29    pub use ::std::{string, vec};
30}
31
32/// Build a `Vec<EntityPathPart>`:
33/// ```
34/// # #![no_std] // test that the macro does not depend on the std *prelude*
35/// # extern crate std;
36/// # fn main() {
37/// # use std::vec::Vec;
38/// # use re_log_types::*;
39/// let parts: Vec<EntityPathPart> = entity_path_vec!("foo", 42, "my image!");
40/// # }
41/// ```
42#[macro_export]
43macro_rules! entity_path_vec {
44    () => {
45        // A vector of no elements that nevertheless has the expected concrete type.
46       $crate::path::__private::vec::Vec::<$crate::EntityPathPart>::new()
47    };
48    ($($part: expr),* $(,)?) => {
49        $crate::path::__private::vec![ $($crate::EntityPathPart::from(
50            $crate::path::__private::string::ToString::to_string(&$part)
51        ),)+ ]
52    };
53}
54
55/// Build an [`EntityPath`] from parts that are _not_ escaped:
56///
57/// ```
58/// # use re_log_types::*;
59/// let path: EntityPath = entity_path!("world", 42, "my image!");
60/// assert_eq!(path, EntityPath::parse_strict(r"world/42/my\ image\!").unwrap());
61/// ```
62#[macro_export]
63macro_rules! entity_path {
64    ($($part: expr),* $(,)?) => {
65        $crate::EntityPath::from($crate::entity_path_vec![ $($part,)* ])
66    };
67}
68
69#[cfg(test)]
70mod tests {
71    use super::*;
72
73    #[test]
74    fn entity_path_macros_empty() {
75        // If the type weren't constrained, this would be an ambiguous type error.
76        assert_eq!(entity_path_vec!(), vec![]);
77        assert_eq!(entity_path!(), EntityPath::from(vec![]));
78    }
79}