oxedyne/fe2o3/fe2o3_infer/src/macros.rs
553 bytes, 1 run
created by r1870400018:19735, which is this file's identity for as long as the history lasts, whatever it is later renamed to
download · who wrote it · its history
| 1 | //! One convenience macro, for the shape of failure this crate meets most. |
| 2 | |
| 3 | /// Unwraps an `Option`, returning a tagged error when it is absent. |
| 4 | /// |
| 5 | /// `fe2o3_core` gives `ok!` for the `Result` case and nothing for the `Option` |
| 6 | /// case, so a loader that asks a model for a weight it does not carry would |
| 7 | /// otherwise be written as a five-line `match` two dozen times over. |
| 8 | #[macro_export] |
| 9 | macro_rules! some { |
| 10 | ($opt:expr, $($arg:expr),+ $(,)?) => { |
| 11 | match $opt { |
| 12 | Some(v) => v, |
| 13 | None => return Err(err!($($arg),+ ; Invalid, Missing)), |
| 14 | } |
| 15 | }; |
| 16 | } |