Macro janetrs::bad_slot

source ·
macro_rules! bad_slot {
    ($args:ident, $index:expr, $expected:expr) => { ... };
}
Expand description

A macro helper to use the default message when getting the wrong types in the function argument when the situations that are more complex than the ones handled in JanetArgs, like multiple accepted types.

§Examples

use janetrs::{bad_slot, janet_fn, Janet, TaggedJanet};

#[janet_fn(arity(fix(1)))]
fn hi(args: &mut [Janet]) -> Janet {
    match args[1].unwrap() {
        TaggedJanet::Buffer(name) => println!("Hi, {}", name),
        TaggedJanet::String(name) => println!("Hi, {}", name),
        _ => bad_slot!(args, 0, "string|buffer"),
    }
    Janet::nil()
}