17 stable releases

2.5.0 Jul 31, 2023
2.4.0 Mar 17, 2023
2.3.0 Apr 27, 2021
2.2.1 Mar 31, 2021
1.2.0 Feb 11, 2018

#194 in Operating systems

Download history 56/week @ 2024-07-29 40/week @ 2024-08-05 90/week @ 2024-08-12 25/week @ 2024-08-19 112/week @ 2024-08-26 40/week @ 2024-09-02 49/week @ 2024-09-09 26/week @ 2024-09-16 40/week @ 2024-09-23 98/week @ 2024-09-30 50/week @ 2024-10-07 56/week @ 2024-10-14 81/week @ 2024-10-21 44/week @ 2024-10-28 63/week @ 2024-11-04 26/week @ 2024-11-11

223 downloads per month
Used in 11 crates (7 directly)

MIT license

32KB
395 lines

Build Status Generic badge Generic badge Generic badge

Simpath

A small and simple crate (in the spirit of my "simp*" crates) for search paths, like $PATH and $LD_PATH.

Example

Create a Simpath that loads from the $PATH environment variable using:

let path = simppath::new("PATH");

Then find a file called filename by searching the directories in PATH in order - as a PathBuf

let file = path.find("filename");

Platforms

The following platforms are supported and tested in CI

  • Linux
  • MacOS
  • Windows (with the ";" separator character used for parsing paths from environment variables)

Methods

  • create a search path, initialized from an environment variable
  • create a search path, initialized form an environment variable, using a custom separator character
  • add an entry to the search path (default to assuming it is a directory)
  • add a new directory to the search path
  • get the name of the path
  • get the list of directories in the path
  • find a file in the path
  • find a file by FileType in the path
  • check if the search path already contains a directory entry
  • add to the search path, loading the entries from an environment variable
  • add to the search path, loading the entries from an environment variable, using a custom separator character
  • validate that all directory entries in the path are valid, exist and can be read

Optional methods

These methods are activated by the "urls" feature, which is included by default.

To remove that code and dependencies disable all default features using the cargo command line option --no-default-features or including default-features = false in your Cargo.toml section for Simpath

  • find a file/resource by FileType in the path
  • Add an entry to the search path from a String, can be a directory or a Url
  • Add a URL to the search path

Traits

  • implements the fmt::Display trait
  • Derives Clone
  • Derives Debug

Building

A simple Makefile exists that builds, runs clippy and then runs tests.

Just type make at the command prompt.

Dependencies

~0–8.5MB
~72K SLoC