Giter VIP home page Giter VIP logo

clircle's Introduction

Clircle

CI crates.io version MSRV

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.

Why?

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.

Why should I use this and not just 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.

Where did this crate come from?

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

  • useful for other projects and
  • too platform specific for bats scope.

So now, you can use clircle too!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.