
# rustypath
Path crate for rust. Managing paths made easy.
## Overview
Coverting and Managing paths in rust is now made easy.
## Table of contents
- [Add to your project](#add-to-your-project)
- [Features](#features)
- [Usage](#usage)
- [Issues](#issues)
## Add to your project
```bash
cargo add rustypath
```
## Features
In `v1.0.0` and above, the code has been divided into features due to growing functionality. The features are listed below:
- `Creation`: This feature is kind of a default feature as this allows users to create a `RPath` struct from these -> [`String`, `&str`, `Path`, `PathBuf`].
- `Management`: This feature will be enabled by default and contains methods to manage/manipulate paths.
- `Conversion`: This feature contains all conversion methods from `RPath` to different path types.
- `Boolean`: This feature contains all boolean type methods for checks.
## Usage
- Importing
```rust
use rustypath::RPath; ```
`Note:` Implementation includes -> [`Clone`, `Debug`, `PartialEq`, `Eq`, `PartialOrd`, `Ord`, `Hash`] and a custom trait for printing `RPath`.
```rust
use rustypath::Display;
```
- Creating `RPath`
- From `&str`, `Path` and `PathBuf`
```rust
let rpath_str = RPath::from(value);
let rpath = RPath::from("/temp");
let rpath_ = RPath::from(std::path::Path::new("/temp"));
let rpath__ = RPath::from(std::path::PathBuf::from("/temp"));
```
- Allocate an empty `RPath`
```rust
let rpath_empty_or_new = RPath::new();
```
- Path Manipulation
- Join
```rust
let rpath = RPath::from("/temp");
let new = rpath.join("abc.txt");
new.print();
```
- Join Multiple
```rust
let mut rpath = RPath::from("/temp");
rpath.join_multiple(vec![value1, value2, ...]);
rpath.print();
```
- Basename/Filename
```rust
let rpath: Rpath = RPath::from("/temp/abc.txt");
let basename: &str = rpath.basename();
```
- Replace Basename
```rust
let rpath = RPath::from("/temp/abc.txt");
let rpath_ = rpath.with_basename("xyz.txt"); ```
- Dirname/Parent
```rust
let rpath: RPath = RPath::from("/temp/abc.txt");
let parent: RPath = rpath.dirname(); ```
- Replace Dirname/Parent
```rust
let rpath: RPath = RPath::from("/temp/abc.txt");
let new = rpath.with_dirname("/temp/temp2"); ```
- Extention
```rust
let rpath = RPath::from("/temp/abc.txt");
let extension: &str = rpath.extension();
```
- Expand
```rust
let rpath = RPath::from("./temp");
let expanded = rpath.expand(); ```
- Read_Dir (return an iterator with DirEntry)
```rust
let rpath = RPath::from("/temp");
for entry in rpath.read_dir().expect("Failed to call read_dir") {
if let Ok(entry) = entry {
println!("{:?}", entry.path());
}
}
```
- Get Current Working Directory
```rust
let current_dr: RPath = RPath::pwd();
```
- Get Home dir of your OS
```rust
let home: RPath = RPath::gethomedir();
```
- Clear the current RPath buffer
```rust
let rpath = RPath::from("/temp");
rpath.clear(); ```
- Conversion
- Convert to string
```rust
let rpath = RPath::from("/abc");
let rpath_string = rpath.convert_to_string();
```
- Convert to PathBuf
```rust
let rpath = RPath::from("/abc");
let rpath_in_pathbuf = rpath.convert_to_pathbuf();
```
- Boolean
- exists
```rust
let rpath = RPath::from("/abc");
if rpath.exists() {
}
```
- is_dir/is_file
```rust
let rpath = RPath::from("/abc");
if rpath.is_dir() {
} else if rpath.is_file() {
}
```
Similarly, the following will work:
- is_absolute
- is_symlink
- is_relative
- Printing
`RPath` supports printing as a single string.
To use the `.print()` function, import `Display` trait
```rust
use rustypath::Display;
```
Printing using `.print()` method.
```rust
let rpath = RPath::gethomedir();
rpath.print();
```
To print with other strings:
```rust
let rpath = RPath::gethomedir();
println!("Homedir: {}", rpath.convert_to_string());
println!("{:?}", rpath);
```
- Operators
- Supports `==` and `!=` operators
```rust
let rpath = RPath::pwd();
let rpath_ = RPath::gethomedir();
if rpath == rpath_ {
} else {
}
```
- Supports Hash
## Issues
If any issues were found kindly add 'em [here](https://github.com/d33pster/rustypath/issues).
## Pull Requests
Pull requests are encouraged and can be added [here](https://github.com/d33pster/rustypath).