Home

Awesome

camino - UTF-8 paths

camino on crates.io crates.io download count Documentation (latest release) Documentation (main) License License

This repository contains the source code for camino, an extension of the std::path module that adds new Utf8PathBuf and Utf8Path types.

What is camino?

camino's Utf8PathBuf and Utf8Path types are like the standard library's PathBuf and Path types, except they are guaranteed to only contain UTF-8 encoded data. Therefore, they expose the ability to get their contents as strings, they implement Display, etc.

The std::path types are not guaranteed to be valid UTF-8. This is the right decision for the standard library, since it must be as general as possible. However, on all platforms, non-Unicode paths are vanishingly uncommon for a number of reasons:

Therefore, many programs that want to manipulate paths do assume they contain UTF-8 data, and convert them to strs as necessary. However, because this invariant is not encoded in the Path type, conversions such as path.to_str().unwrap() need to be repeated again and again, creating a frustrating experience.

Instead, camino allows you to check that your paths are UTF-8 once, and then manipulate them as valid UTF-8 from there on, avoiding repeated lossy and confusing conversions.

Examples

The documentation for Utf8PathBuf and Utf8Path contains several examples.

For examples of how to use camino with other libraries like serde and clap, see the camino-examples directory.

API design

camino is a very thin wrapper around std::path. Utf8Path and Utf8PathBuf are drop-in replacements for Path and PathBuf.

Most APIs are the same, but those at the boundary with str are different. Some examples:

Every Utf8Path is a valid Path, so Utf8Path implements AsRef<Path>. Any APIs that accept impl AsRef<Path> will continue to work with Utf8Path instances.

Should you use camino?

camino trades off some utility for a great deal of simplicity. Whether camino is appropriate for a project or not is ultimately a case-by-case decision. Here are some general guidelines that may help.

You should consider using camino if...

In general, using camino is the right choice for most projects.

You should NOT use camino, if...

Optional features

By default, camino has no dependencies other than std. There are some optional features that enable dependencies:

NOTE: Enabling the serde or proptest features will not do anything. You must enable the serde1 and proptest1 features, respectively.

Rust version support

The minimum supported Rust version (MSRV) for camino with default features is 1.34. This project is tested in CI against the latest stable version of Rust and the MSRV.

camino is designed to be a core library and has a conservative MSRV policy. MSRV increases will only happen for a compelling enough reason, and will involve at least a minor version bump.

Optional features may pull in dependencies that require a newer version of Rust.

License

This project is available under the terms of either the Apache 2.0 license or the MIT license.

This project's documentation is adapted from The Rust Programming Language, which is available under the terms of either the Apache 2.0 license or the MIT license.