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

File-like entity paths #4476

Merged
merged 13 commits into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from 10 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
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ memory-stats = "1.1"
mimalloc = "0.1.29"
mime = "0.3"
mime_guess = "2.0"
natord = "1.0.9"
ndarray = "0.15"
ndarray-rand = "0.14"
never = "0.1"
Expand Down
2 changes: 1 addition & 1 deletion crates/re_data_store/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pub use self::versioned_instance_path::{VersionedInstancePath, VersionedInstance
pub(crate) use self::entity_tree::{ClearCascade, CompactedStoreEvents};

use re_log_types::DataTableError;
pub use re_log_types::{EntityPath, EntityPathPart, Index, TimeInt, Timeline};
pub use re_log_types::{EntityPath, EntityPathPart, TimeInt, Timeline};

#[cfg(feature = "serde")]
pub use blueprint::EntityPropertiesComponent;
Expand Down
8 changes: 4 additions & 4 deletions crates/re_log_encoding/benches/msg_encode_benchmark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ compile_error!("msg_encode_benchmark requires 'decoder' and 'encoder' features."
static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc;

use re_log_types::{
entity_path, DataRow, DataTable, Index, LogMsg, RowId, StoreId, StoreKind, TableId, TimeInt,
TimeType, Timeline,
entity_path, DataRow, DataTable, LogMsg, RowId, StoreId, StoreKind, TableId, TimeInt, TimeType,
Timeline,
};
use re_types::datagen::{build_some_colors, build_some_positions2d};

Expand Down Expand Up @@ -73,7 +73,7 @@ fn mono_points_arrow(c: &mut Criterion) {
TableId::ZERO,
[DataRow::from_cells2(
RowId::ZERO,
entity_path!("points", Index::Sequence(i as _)),
entity_path!("points", i.to_string()),
[build_frame_nr(0.into())],
1,
(build_some_positions2d(1), build_some_colors(1)),
Expand Down Expand Up @@ -131,7 +131,7 @@ fn mono_points_arrow_batched(c: &mut Criterion) {
(0..NUM_POINTS).map(|i| {
DataRow::from_cells2(
RowId::ZERO,
entity_path!("points", Index::Sequence(i as _)),
entity_path!("points", i.to_string()),
[build_frame_nr(0.into())],
1,
(build_some_positions2d(1), build_some_colors(1)),
Expand Down
1 change: 1 addition & 0 deletions crates/re_log_types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ fixed = { version = "1.17", default-features = false, features = ["serde"] }
# we keep it as a direct dependency to ensure it stays pinned on `2.2.1`
half.workspace = true
itertools.workspace = true
natord.workspace = true
nohash-hasher.workspace = true
num-derive.workspace = true
num-traits.workspace = true
Expand Down
138 changes: 0 additions & 138 deletions crates/re_log_types/src/index.rs

This file was deleted.

2 changes: 0 additions & 2 deletions crates/re_log_types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ mod data_table;
#[cfg(feature = "testing")]
pub mod example_components;
pub mod hash;
mod index;
mod num_instances;
pub mod path;
mod time;
Expand All @@ -49,7 +48,6 @@ pub use self::data_table::{
ErasedTimeVec, NumInstancesVec, RowIdVec, TableId, TimePointVec, METADATA_KIND,
METADATA_KIND_CONTROL, METADATA_KIND_DATA,
};
pub use self::index::*;
pub use self::num_instances::NumInstances;
pub use self::path::*;
pub use self::time::{Duration, Time, TimeZone};
Expand Down
36 changes: 19 additions & 17 deletions crates/re_log_types/src/path/entity_path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,29 +67,28 @@ impl std::fmt::Debug for EntityPathHash {

// ----------------------------------------------------------------------------

/// The unique identifier of an entity, e.g. `camera/"ACME Örnöga"/points`
/// The unique identifier of an entity, e.g. `camera/3/points`
///
/// The entity path is a list of [parts][EntityPathPart] separated by slashes.
/// Each part is a non-empty string, that can contain any character.
/// When written as a string, some characters in the parts need to be escaped with a `\`
/// (only character, numbers, `.`, `-`, `_` does not need escaping).
///
/// Each part is either a [_name_][EntityPathPart::Name] of a limited set of characters,
/// or an [`Index`][crate::Index].
/// Names are like idenitifers in code, and must match the regex: `[a-zA-z0-9_-]+`
/// Indices are like array indices or keys in a map or table, and can be any string,
/// uuid, or number.
/// See <https://www.rerun.io/docs/concepts/entity-path> for more on entity paths.
///
/// Reference-counted internally, so this is cheap to clone.
///
/// Implements [`nohash_hasher::IsEnabled`].
/// `EntityPath` is reference-counted internally, so it is cheap to clone.
/// It also has a precomputed hash and implemented [`nohash_hasher::IsEnabled`],
/// so it is very cheap to use in a [`nohash_hasher::IntMap`] and [`nohash_hasher::IntSet`].
///
/// ```
/// # use re_log_types::{EntityPath, EntityPathPart, Index};
/// # use re_log_types::EntityPath;
/// assert_eq!(
/// EntityPath::parse_strict(r#"camera/"ACME Örnöga"/points/#42"#).unwrap(),
/// EntityPath::parse_strict(r#"camera/ACME\ Örnöga/points/42"#).unwrap(),
/// EntityPath::new(vec![
/// EntityPathPart::Name("camera".into()),
/// EntityPathPart::Index(Index::String("ACME Örnöga".into())),
/// EntityPathPart::Name("points".into()),
/// EntityPathPart::Index(Index::Sequence(42))
/// "camera".into(),
/// "ACME Örnöga".into(),
/// "points".into(),
/// "42".into(),
/// ])
/// );
/// ```
Expand Down Expand Up @@ -124,15 +123,18 @@ impl EntityPath {
}

/// Treat the string as one opaque string, NOT splitting on any slashes.
pub fn from_single_string(string: String) -> Self {
Self::new(vec![EntityPathPart::Index(crate::Index::String(string))])
///
/// The given string is expected to be unescaped, i.e. any `\` is treated as a normal character.
pub fn from_single_string(string: impl Into<String>) -> Self {
Self::new(vec![EntityPathPart::new(string)])
}

#[inline]
pub fn iter(&self) -> impl Iterator<Item = &EntityPathPart> {
self.path.iter()
}

#[inline]
pub fn last(&self) -> Option<&EntityPathPart> {
self.path.last()
}
Expand Down
7 changes: 3 additions & 4 deletions crates/re_log_types/src/path/entity_path_impl.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::path::EntityPathPart;

/// `camera / "left" / points / #42`
/// `camera/left/points/42`
///
/// Wrapped by [`crate::EntityPath`] together with a hash.
#[derive(Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
Expand Down Expand Up @@ -83,9 +83,8 @@ where

impl std::fmt::Debug for EntityPathImpl {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
// Show the nicely formatted entity path, but surround with quotes and escape
// troublesome characters such as back-slashes and newlines.
write!(f, "{:?}", self.to_string())
// Like `Display`, but with quotes
write!(f, "'{self}'")
}
}

Expand Down
Loading
Loading