Skip to content

AlexIndustrial/extended_rust

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Extended Rust

A set of handy macros for your Rust projects

MIT License

Installation

Install Extended Rust with cargo

# cargo.toml:
extended_rust = { git = "https://github.com/AlexIndustrial/extended_rust.git" }

Usage/Examples

Create String

let my_string = string!(); // String::new()

let my_string = string!("hello world");
// "hello world".to_string()

Conversion of Option to Result and conversely

let option: Option<String>= Some(string!("hello world"));

let result: Result<String, ()> = to_result!(option);
let result_with_err: Result<String, i32> = to_result!(option, 10); 

let back_to_opt: Option<String> = to_option!(result);
let back_to_opt: Option<String> = to_option!(result_with_err);

Returns by type

some_return!(option, string!("return this if option is Some"));
none_return!(option, string!("return this if option is None"));

ok_return!(result, string!("return this if result is Ok"));
err_return!(result, string!("return this if result is Err"));

Quick return result

ok!(string!("data")); // return Ok(string!("data"))
err!(string!("data")); // return Err(string!("data"))

Io Result

fn main() -> io_result!(()) /* std::io::Result<()> */ {
    Ok(())
}

Prints

q_print_obj!(obj); // println!("{:?}", obj)
q_print!("data") // println!("{}", "data")

About

A set of handy macros for your Rust projects

Resources

Stars

Watchers

Forks

Releases

Packages

Used by

Contributors

Languages