try_ops 0.1.1

try catc... ops macro
Documentation
  • Coverage
  • 50%
    1 out of 2 items documented0 out of 0 items with examples
  • Size
  • Source code size: 4.76 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.03 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Links
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • pgjbz

Ops

What is Ops?

It's just a joke with "try { bla bla bla } catch (NullPointerException e) { bla bla bla bla }".

But i use ops,

It's created only for pratice declarative Rust macros.

But it's functional macro.

Usage:

use std::fmt::Display;

use ops::catch;

fn main() {
    catch!{() =>
        try {
            error()?;
            Ok(())
        } ops e: NullPointerException {
            //do something
            println!("{}", e)
        }
    }
}

#[derive(Debug)]
struct NullPointerException {
    message: String,
}

impl NullPointerException {
    fn new(message: &str) -> Self {
        Self { message: message.into() }
    }
}

impl Display for NullPointerException {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        write!(f, "NullPointerException: {}", self.message)
    }
}

impl std::error::Error for NullPointerException {}

//some stuff
fn error() -> Result<(), Box<dyn std::error::Error>> {
    Err(Box::new(NullPointerException::new("get out of here")))
}

The macro expand to: