Macro janetrs::table [−][src]
macro_rules! table { () => { ... }; ($($key:expr => $value:expr),* $(,)?) => { ... }; }
Expand description
Creates a JanetTable
containing the arguments key-value pairs.
table!
allows JanetTable
s to be defined with a syntax that have key-value
pairs as the items of the struct.
use janetrs::{table, Janet}; let table = table! { 1 => "one", true => 1, }; assert_eq!(table.len(), 2); assert_eq!(table.get(1), Some(&Janet::from("one"))); assert_eq!(table.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.