5 unstable releases

0.3.1 Jan 3, 2024
0.3.0 Sep 14, 2023
0.2.0 Mar 19, 2023
0.1.1 Mar 17, 2023
0.1.0 Mar 17, 2023

#978 in Rust patterns

Download history 60/week @ 2023-12-18 6/week @ 2024-01-01 4/week @ 2024-02-26 142/week @ 2024-03-11

146 downloads per month
Used in asahi-portable

MIT license

5KB
84 lines

SmURF

SMall Useful Rust Functions

Components

IO

  • macros input!(T) and input_vec!(T), that could be used to simplify stdin process
  • read_file_str() basically reads file to string (yes.)
  • read_file_bytes() see read_file_str()

Shell

  • macros shell!()

Usage

Add this to your Cargo.toml:

[dependencies]
smurf = "0.3"

and this to your crate root:

extern crate smurf;

Example

use smurf;
use std::io::Write;

fn main() {
	print!("What is your name? ");
	std::io::stdout().flush().unwrap();
	let user_name = input!(String);
	print!("What is your age? ");
	std::io::stdout().flush().unwrap();
	let user_age = input!(u8);
	let shell_output = shell!("echo Hello {} of age {}", user_name, user_age); // Returns ShellResult {code: i32, stdout: String, stderr: String}
	println!("Shell output: {}", shell_output.stdout);
	println!("Shell stderr: {}", shell_output.stderr);
	println!("Shell exit code: {}", shell_output.code);
}

License

MIT

No runtime deps