Skip to content

Commit

Permalink
support building hierarchical entity path from file path
Browse files Browse the repository at this point in the history
  • Loading branch information
teh-cmc committed Dec 14, 2023
1 parent f68b0b6 commit bb050f7
Show file tree
Hide file tree
Showing 3 changed files with 19 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
18 changes: 17 additions & 1 deletion crates/re_log_types/src/path/entity_path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,27 @@ 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()
// NOTE: This can only happen when hitting the leading `/` in an absolute path, and
// we currently don't support entity paths with leading `/`s.
.filter(|p| p != &std::ffi::OsStr::new("/"))
.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 bb050f7

Please sign in to comment.