# SKN Rust Utility Library
> Rust
[![Crates IO](https://img.shields.io/crates/v/best_skn_utils)](https://crates.io/crates/best_skn_utils) [![MIT License](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/license/mit)
## **_RustDocs:_**
### Read the Rustdoc for the main Modules
- [env](https://docs.rs/best_skn_utils/1.2.3/best_skn_utils/env/index.html)
- [execution](https://docs.rs/best_skn_utils/1.2.3/best_skn_utils/execution/index.html)
- [stdio](https://docs.rs/best_skn_utils/1.2.3/best_skn_utils/stdio/index.html)
- [random](https://docs.rs/best_skn_utils/1.2.3/best_skn_utils/random/index.html)
- [args](https://docs.rs/best_skn_utils/1.2.3/best_skn_utils/args/index.html)
## **_Introduction:_**
### This is a simple Rust Library for some essential utility functions
### I made this library so that I can use it in all of my rust projects without writing the same codes over and over again
### The main Modules of this library are `env`, `execution`, `stdio`, `random` & `args`
## **_Details:_**
### **`env` Module:**
- It has 1 function which builds external config file functionality to get data from outside the program
- `init_config` function takes generic
- The file name is `rustenv.toml` from which you can get data after invoking the function
- The config file `rustenv.toml` must be placed in the root directory where `Cargo.toml` file is
- To read values from the file properly you need [serde](https://crates.io/crates/serde) crate
- See `Usage` section to get an example of how to use it
### **`execution` Module**
- It has 2 functions which help to execute commands in the terminal
- `execute_command` function can run any command in the terminal
- it takes the command name as first argument
- it takes a reference of string slice (&str) array as command arguments
- `gnome_execute_command` function can open a new gnome terminal and executes commands in it
- it takes only one argument which is a string slice (&str)
- if multiple command needs to be executed then the commands must be separated by `;`
- See `Usage` section to get an example of how to use it
### **`stdio` Module**
- It has 1 function which reads user input and returns it
- `read_line` function returns String if it successfully reads the input else returns Error
- See `Usage` section to get an example of how to use it
### **`random` Module**
- It has 1 function that generates random number from a given range
- `gen_random_number` function takes two parameters to set a range. One is `low` and the other one is `high`
- The parameters can either be `Integer` or `Float`
- parameter `low` and `high` must be of same type i.e. you cannot set a range of say from 1 to 10.1
- The second parameter `high` is inclusive i.e. a range of 1 and 10 will mean the range includes from 1 to 10
- See `Usage` section to get an example of how to use it
### **`args` Module**
- It has 1 function that provides a collection of arguments passed in command line interface
- `get_args` function returns a collection as a vector of String
- See `Usage` section to get an example of how to use it
## **_Use Case:_**
- Rust
## **_Requirements:_**
- ๐ Minimum Rust Version: `1.80.0`
- ๐ Crates:
- [serde](https://crates.io/crates/serde): `1.0.208`
- [num](https://crates.io/crates/num): `0.4.3`
- [rand](https://crates.io/crates/rand): `0.8.5`
- [config](https://crates.io/crates/config): `0.14.0`
## **_Usage:_**
### To install the package, type the following in console
> ```zsh
> cargo add best_skn_utils
> ```
### Inside your Rust Code, import the package like this
> ```rust
> use best_skn_utils::{env, execution, stdio, random, args};
> ```
### Use the modules like the following (Just an example)
#### (1) For `env` module, you can use like this
##### **(a) Suppose the `rustenv.toml` file contains the data like this**
> ```toml
> [author]
> name = "SKN"
> email = "skn437physx@gmail.com"
> ```
##### **(b) Then the usage of the module can be like this**
> ```rust
> use best_skn_utils::env::init_config;
> use serde::Deserialize;
>
> #[derive(Debug, Deserialize)]
> struct Author {
> name: String,
> email: String,
> }
>
> impl Author {
> fn new() -> Self {
> Self {
> name: String::new(),
> email: String::new(),
> }
> }
> }
>
> #[derive(Debug, Deserialize)]
> struct ConfigData {
> author: Author,
> }
>
> impl ConfigData {
> fn new() -> Self {
> let config = init_config::();
>
> match config {
> | Ok(value) => value,
> | Err(e) => {
> println!("Error: {}", e);
> Self {
> author: Author::new(),
> }
> }
> }
> }
> }
>
> let config_data: ConfigData = ConfigData::new();
>
> println!("Name: {}, Email: {}", config_data.author.name, config_data.author.email);
> ```
#### (2) For `execution` module, you can use like this
> ```rust
> use best_skn_utils::execution::{execute_command, gnome_execute_command};
>
> execute_command("cargo", &["doc", "--open"]);
>
> gnome_execute_command("printf 'Hello SKN! \n'; printf 'Build was successful! โ
\n'; read -n 1 KEY");
> ```
#### (3) For `stdio` module, you can use like this
> ```rust
> use best_skn_utils::stdio::read_line;
> use std::io::Error;
>
> let input: Result = read_line("Write your name:");
>
> match input {
> | Ok(value) => println!("Your name: {}", value),
> | Err(e) => println!("Error: {}", e),
> }
> ```
#### (4) For `random` module, you can use like this
> ```rust
> use best_skn_utils::random::gen_random_number;
>
> let num1: i32 = gen_random_number(1, 10);
> let num2: f64 = gen_random_number(1.5, 7.5);
> ```
#### (5) For `args` module, you can use like this
> ```rust
> use best_skn_utils::args::get_args;
>
> let args: Vec = get_args();
>
> println!("{:?}", args);
> ```
## **_Dedicated To:_**
- ๐ฉโโ๏ธ`Tanjila Hasan Trina`: The long lost love of my life. The course of nature separated us from our paths and put us in separate places far away from each other. But no matter how separated we are right now, each and every moment of mine is only dedicated to you. We may not see each other in this lifetime as it seems but I will find you again in the next life. I just want to say: `ไธ็ใฏๆฎ้
ทใ ใใใงใๅใๆใใ`
- ๐ฏ`My Parents`: The greatest treasures of my life ever.
## **_License:_**
Copyright (C) 2024 SKN Shukhan
Licensed under the MIT License