drop_ok

Crates.iodrop_ok
lib.rsdrop_ok
version1.0.2
sourcesrc
created_at2020-08-10 07:16:36.098353
updated_at2020-08-10 08:04:37.231287
description`.drop_ok` syntax sugar for `Result`. It's instead of `.map(|_|())`.
homepage
repositoryhttps://github.com/usagi/drop_ok
max_upload_size
id274958
size6,560
Usagi Ito (usagi)

documentation

https://docs.rs/drop_ok/1.0.2/drop_ok/trait.DropOk.html#example

README

drop_ok

  • This crate defines DropOk<E> trait and impl for Result.
  • DropOk<E> trait has .drop_ok(self) -> Result<(), E> function.
  • This is a syntax sugar for .map(|_|()).

Useful scene

fn some_function() -> Result<(), MyError>
{
 match switcher
 {
  pattern_a => some_task1().drop_ok()?
  pattern_b => some_task2().drop_ok()?
  pattern_c => some_task3()?
  pattern_d => some_task4()
  _ => ()
 }
}

fn some_task1()     -> Result<i8     , MyError> { /* abbr */ }
fn some_task2<'a>() -> Result<&'a str, MyError> { /* abbr */ }
fn some_task3()     -> Result<()     , MyError> { /* abbr */ }
fn some_task4() { /* abbr */ }
  • See also: <tests/test.rs>

Note

"I don't need it, because ..."

  • Yes, your are right to your world.
    • But, I tired to type/see .map(|_|()). So I'm happy with.drop_ok().

LICENSE

Author

Commit count: 7

cargo fmt