Skip to content

Latest commit

 

History

History
24 lines (20 loc) · 853 Bytes

RUST.md

File metadata and controls

24 lines (20 loc) · 853 Bytes
  1. catching unwinds with std::panic::catch_unwind; whereas catch panics and inspect the error messges by changing hooks set_hook & take_hook
        let prev = panic::take_hook();
        panic::set_hook(Box::new(move |info| {
            if let Some(s) = info.payload().downcast_ref::<&str>() {
                if s.starts_with(PARSER_ERR_TAG) {
                    eprintln!("parser error: {s:?}");
                    return;
                }
            }
            prev(info);
        }));

        let result = panic::catch_unwind(AssertUnwindSafe(|| self.expression()));
        return if let Ok(exp) = result {
            Ok(exp)
        } else {
            Err("parser error".to_string())
        };
  1. derive-new : implement simple constructor functions for structs and enums.