From 5a93347043547f48495e656f422557f9755ee803 Mon Sep 17 00:00:00 2001 From: Clement Rey Date: Fri, 15 Dec 2023 11:45:33 +0100 Subject: [PATCH] `DataLoader`s 0: utility for hierarchical `EntityPath` from file path (#4516) A trivial PR that I extracted into its own in case this ends up being controversial. --- Part of a series of PRs to make it possible to load _any_ file from the local filesystem, by any means, on web and native: - #4516 - #4517 - #4518 - #4519 - #4520 - #4521 --- Cargo.lock | 1 + crates/re_log_types/Cargo.toml | 1 + crates/re_log_types/src/path/entity_path.rs | 15 ++++++++++++++- 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index 3f715558c320..5c3a289f1e7c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4631,6 +4631,7 @@ dependencies = [ "arrow2", "backtrace", "bytemuck", + "clean-path", "criterion", "crossbeam", "document-features", diff --git a/crates/re_log_types/Cargo.toml b/crates/re_log_types/Cargo.toml index 79cce06fda9c..89b3157be2d7 100644 --- a/crates/re_log_types/Cargo.toml +++ b/crates/re_log_types/Cargo.toml @@ -50,6 +50,7 @@ arrow2 = { workspace = true, features = [ ] } backtrace.workspace = true bytemuck.workspace = true +clean-path.workspace = true document-features.workspace = true fixed = { workspace = true, default-features = false, features = ["serde"] } # `fixed` depends on `half`, so even though `half` is not directly used in this crate, diff --git a/crates/re_log_types/src/path/entity_path.rs b/crates/re_log_types/src/path/entity_path.rs index 069b2441a154..c20bf8dfc0b4 100644 --- a/crates/re_log_types/src/path/entity_path.rs +++ b/crates/re_log_types/src/path/entity_path.rs @@ -118,11 +118,24 @@ impl EntityPath { /// /// The file path separators will NOT become splits in the new path. /// The returned path will only have one part. - #[cfg(not(target_arch = "wasm32"))] pub fn from_file_path_as_single_string(file_path: &std::path::Path) -> Self { Self::from_single_string(file_path.to_string_lossy().to_string()) } + /// Treat the file path as an entity path hierarchy. + /// + /// The file path separators will become splits in the new path. + pub fn from_file_path(file_path: &std::path::Path) -> Self { + use clean_path::Clean as _; + Self::new( + file_path + .clean() + .iter() + .map(|p| EntityPathPart::from(p.to_string_lossy().to_string())) + .collect(), + ) + } + /// Treat the string as one opaque string, NOT splitting on any slashes. /// /// The given string is expected to be unescaped, i.e. any `\` is treated as a normal character.