├── .gitignore ├── Cargo.toml ├── README.md └── src └── lib.rs /.gitignore: -------------------------------------------------------------------------------- 1 | target 2 | Cargo.lock 3 | -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "yolo" 3 | version = "0.1.2" 4 | authors = ["timglabisch "] 5 | description = "Rusts .yolo()" 6 | documentation = "https://github.com/timglabisch/rust_yolo" 7 | homepage = "https://github.com/timglabisch/rust_yolo" 8 | repository = "https://github.com/timglabisch/rust_yolo.git" 9 | readme = "README.md" 10 | keywords = ["yolo"] 11 | license = "WTFPL" 12 | 13 | [dependencies] 14 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Rust Yolo 2 | 3 | this crate allows using `yolo` instead of the `unwrap` function for Option and Result 4 | example: 5 | 6 | ``` 7 | extern crate yolo; 8 | use yolo::Yolo; 9 | 10 | fn get_result(v : i32) -> Result { 11 | Ok(v) 12 | } 13 | 14 | fn main() { 15 | assert_eq!(Some(123).yolo(), 123); 16 | assert_eq!(get_result(123).yolo(), 123); 17 | 18 | println!("hello world!"); 19 | } 20 | ``` 21 | 22 | installation 23 | 24 | use 25 | 26 | ``` 27 | [dependencies] 28 | yolo = "*" 29 | ``` 30 | 31 | make sure you DONT'T pin it to a version -> YOLO!. 32 | 33 | # special thanks 34 | special thanks to [matthiasendler](https://github.com/mre) who recognized [how important](https://twitter.com/matthiasendler/status/696769903022497792) this crate is 35 | -------------------------------------------------------------------------------- /src/lib.rs: -------------------------------------------------------------------------------- 1 | use std::fmt; 2 | 3 | pub trait Yolo { 4 | fn yolo(self) -> T; 5 | } 6 | 7 | impl Yolo for Option { 8 | fn yolo(self) -> T { 9 | self.unwrap() 10 | } 11 | } 12 | 13 | impl Yolo for Result where E: fmt::Debug { 14 | fn yolo(self) -> T { 15 | self.unwrap() 16 | } 17 | } 18 | 19 | #[cfg(test)] 20 | mod tests { 21 | fn get_result(v: i32) -> Result { 22 | Ok(v) 23 | } 24 | 25 | #[test] 26 | fn it_works() { 27 | assert_eq!(Some(123).yolo(), 123); 28 | assert_eq!(get_result(123).yolo(), 123) 29 | } 30 | } 31 | 32 | --------------------------------------------------------------------------------