Skip to content

Commit

Permalink
DataLoaders 0: utility for hierarchical EntityPath from file path (
Browse files Browse the repository at this point in the history
…#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
  • Loading branch information
teh-cmc authored Dec 15, 2023
1 parent f2382b1 commit 5a93347
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
1 change: 1 addition & 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 crates/re_log_types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
15 changes: 14 additions & 1 deletion crates/re_log_types/src/path/entity_path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 5a93347

Please sign in to comment.