| Crates.io | clircle |
| lib.rs | clircle |
| version | 0.6.1 |
| created_at | 2020-10-31 20:11:21.405755+00 |
| updated_at | 2024-10-24 19:39:11.814969+00 |
| description | Detect IO circles in your CLI apps arguments. |
| homepage | https://github.com/niklasmohrin/clircle |
| repository | https://github.com/niklasmohrin/clircle |
| max_upload_size | |
| id | 307302 |
| size | 47,917 |
Clircle provides a cross-platform API to detect read / write cycles from your user-supplied arguments. You can get the important identifiers of a file (from a path) and for all three stdio streams, if they are piped from or to a file as well.
Imagine you want to read data from a couple of files and output something according to the contents of these files. If the user redirects the output of your program to one of the input files, you might end up in an infinite circle of reading and writing.
The crate provides the struct Identifier which is a platform dependent type alias, so that
you can use it on all platforms and do not need to introduce any conditional compilation
yourself.
On both Unix and Windows systems, Identifier holds information to identify a file on a disk.
The Clircle trait is implemented on both of these structs and requires TryFrom for the
clircle::Stdio enum and for &Path, so that all possible inputs can be represented as an
Identifier.
Finally, Clircle is a subtrait of Eq, so that the identifiers can be conveniently compared
and circles can be detected.
The clircle crate also provides some convenience functions around the comparison of Clircle
implementors.
fs::Metadata?The clircle crate seamlessly works on Linux and Windows through
a single API, so no conditional compilation is needed at all.
Furthermore, MetadataExt is not stable on Windows yet, meaning you
would have to dig into the Windows APIs yourself to get the information
needed to identify a file.
This crate originated in a pull request to the bat project.
The bat tool strives to be a drop-in replacement for the unix tool cat.
Since cat detects these cycles, bat has to do so too, which is where most
of this code came into play. However, it was decided, that the new logic was
bats scope.So now, you can use clircle too!