Git Product home page Git Product logo

paths's Introduction

paths

Simple way to semantically require relative or absolute paths.

tl;dr;

There are three main classes in this crate that have various constraints that are validated by their constructors. See try_new on each of these classes.

Each set of constraints has a *Path and *PathBuf variant, mirroring what is in the standard lib:

  • RelativePath / RelativePathBuf: These paths must not start with /
  • AbsolutePath / AbsolutePathBuf: These paths must start with a / and be a complete path.
  • CombinedPath / CombinedPathBuf: These paths may be either a relative or absolute one.

Adding to a project

# Cargo.toml
[dependencies]
paths = { git = "https://github.com/nataliejameson/paths", tag = "0.1.0" }

Extra features

If the serde feature is enabled, a serialization / deserialization impl is made available that also validates path constraints on deserialization. If the diesel feature is enabled, a field type is added that allows serialization and deserialization in Diesel (ToSql/FromSql impls are provided)

Random notes

For CombinedPath, CombinedPath::try_into_absolute() and CombinedPath::try_into_absolute_in_cwd() can be used to either return an absolute path, or resolve it against an absolute path if the inner data is a relative path.

Because FromStr is implemented, things like CombinedPathBuf can be used by clap.

Like Path, the *Path implementations are ~zero size containers over the inner Path reference object. It's similar in the case of PathBuf variants.

These types all can deref into Path like structs, so pretty much any stdlib functions should work with them.

paths's People

Contributors

nataliejameson avatar

Watchers

 avatar

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.