Macro janetrs::structs

source ·
macro_rules! structs {
    ($($key:expr => $value:expr),* $(,)?) => { ... };
}
Expand description

Creates a JanetStruct containing the arguments key-value pairs.

structs! allows JanetStructs to be defined with a syntax that have key-value pairs as the items of the struct.

use janetrs::{structs, Janet};

let st = structs! {
    1 => "one",
    true => 1,
};

assert_eq!(st.len(), 2);
assert_eq!(st.get(1), Some(&Janet::from("one")));
assert_eq!(st.get(true), Some(&Janet::integer(1)));

Note that this macro builds the struct converting the passed elements to Janet using the From trait, so if you want for a type defined by you to be used in this macro, implement the From trait to convert from you type to Janet or transform to Janet beforehand.