From be4bc4abe192080926a6c3cd73b6b7667fa286f0 Mon Sep 17 00:00:00 2001 From: Sathish Date: Sun, 19 Sep 2021 15:38:21 +0530 Subject: [PATCH] fix docs --- README.md | 16 ++++++++++++++++ src/lib.rs | 14 ++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/README.md b/README.md index 807caa0..5b04d35 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,18 @@ # untildify Utility to replace ~ with user home directory + +## Example + +```rust +extern crate untildify; + +fn main() { + println!("Untildify : {}", untildify::untildify("~/Desktop")); + // prints /Users//Desktop + + // Other Examples + // assert_eq!(untildify("~/a/b/c/d/e"), "/User/Untildify/a/b/c/d/e"); + // assert_eq!(untildify("~/"), "/User/Untildify/"); +} + +``` \ No newline at end of file diff --git a/src/lib.rs b/src/lib.rs index d39bb5f..27534f1 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -2,6 +2,20 @@ use regex::Regex; use std::env; use std::path::PathBuf; +/// Convert a tilde path to an absolute path: ~/Desktop → /Users/sathish/Desktop +/// +/// Example +/// +/// ``` +/// use untildify::untildify; +/// +/// fn main() { +/// println!("Untildify : {}", untildify::untildify("~/Desktop")); // prints /Users//Desktop +/// println!("Untildify : {}", untildify("~/a/b/c/d/e")); // prints "/User/Untildify/a/b/c/d/e" +/// println!("Untildify : {}", untildify("~/")); // prints "/User/Untildify/" +/// } +/// ``` + pub fn untildify(input_path: &str) -> String { if input_path.is_empty() { return String::from(input_path);