mismatched types in macro_rules
#[macro_export] macro_rules! constrain { ($n:expr, $type_name:expr $(, $arg:expr )*) => {{ use crate::ErrorKind; use crate::Error; let args: &[i64] = &[$($arg),*]; let (min, max) = match args.len() { 0 => (0, i64::MAX), 1 => (0, args[0]), 2 => (args[0], args[1]), _ => return Err(Error::from_kind(ErrorKind::RangeError(“Invalid arguments”.to_string()))), }; if $n < min || $n > max { return […]
Position independent named arguments in a Rust macro
Background I have a crate https://crates.io/crates/magic_migrate that provides a trait TryMigrate. I’m working on writing a macro that allows someone to define this trait by providing an error and a “chain” of structs that define a migration order. Eventually I would like to make an even-more generic macro that takes three things (error, deserializer, and […]