try_ops

Crates.iotry_ops
lib.rstry_ops
version0.1.1
sourcesrc
created_at2022-07-06 18:00:04.771383
updated_at2022-07-07 13:43:06.975395
descriptiontry catc... ops macro
homepage
repository
max_upload_size
id620632
size5,106
Paulo G.J. Bezerra (pgjbz)

documentation

README

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:


Commit count: 0

cargo fmt