Rust
ย
ย
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
ย
- 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 whereCargo.toml
file is - To read values from the file properly you need serde crate
- See
Usage
section to get an example of how to use it
- 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
- 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
- It has 1 function that generates random number from a given range
gen_random_number
function takes two parameters to set a range. One islow
and the other one ishigh
- The parameters can either be
Integer
orFloat
- parameter
low
andhigh
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
- 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
ย
- Rust
ย
ย
cargo add best_skn_utils
use best_skn_utils::{env, execution, stdio, random, args};
[author] name = "SKN" email = "[email protected]"
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::<Self>(); 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);
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");
use best_skn_utils::stdio::read_line; use std::io::Error; let input: Result<String, Error> = read_line("Write your name:"); match input { | Ok(value) => println!("Your name: {}", value), | Err(e) => println!("Error: {}", e), }
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);
use best_skn_utils::args::get_args; let args: Vec<String> = get_args(); println!("{:?}", args);
ย
- ๐ฉโโ๏ธ
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.
ย
Copyright (C) 2024 SKN Shukhan
Licensed under the MIT License