Consider using the camino crate for UTF-8 paths #5

Open
opened 2025-10-03 22:55:11 +02:00 by federico · 1 comment
Collaborator

Rust's standard library represents file paths as PathBuf which Deref to Path. Individual path components are returned as OsStr slices. Neither of those types can be assumed to be a UTF-8 &str, and as you doubtless have found, this is a pain in the ass for code which is not a file manager which must be able to operate on inconsistently-encoded directory trees.

I think we can safely assume that Fipamo's directory trees will have only valid UTF-8 filenames. If that is the case, the camino crate makes it a lot easier to deal with UTF-8 filenames, since everything there is a &str.

Rust's standard library represents file paths as [`PathBuf`](https://doc.rust-lang.org/std/path/struct.PathBuf.html) which `Deref` to [`Path`](https://doc.rust-lang.org/std/path/struct.Path.html). Individual path components are returned as [`OsStr`](https://doc.rust-lang.org/std/ffi/struct.OsStr.html) slices. Neither of those types can be assumed to be a UTF-8 `&str`, and as you doubtless have found, this is a pain in the ass for code which is not a file manager which must be able to operate on inconsistently-encoded directory trees. I think we can safely assume that Fipamo's directory trees will have only valid UTF-8 filenames. If that is the case, the [`camino`](https://lib.rs/crates/camino) crate makes it a lot easier to deal with UTF-8 filenames, since everything there is a `&str`.
Collaborator

Gotcha. I'll give it a look.

Gotcha. I'll give it a look.
Sign in to join this conversation.
No labels
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
projects/love_fipamo#5
No description provided.