macro_rules! tuple { ($elem:expr; $n:expr) => { ... }; ($($val:expr),* $(,)?) => { ... }; }
Expand description
Creates a JanetTuple
containing the arguments.
tuple!
allows JanetTuple
s to be defined with the same syntax as Rust array
expressions. There are 2 forms of this macro:
- Create a
JanetTuple
containing a given list of elements
use janetrs::{tuple, Janet};
let t = tuple![3, true, "hey"];
assert_eq!(t[0], &Janet::integer(3));
assert_eq!(t[1], &Janet::boolean(true));
assert_eq!(t[2], &Janet::from("hey"));
- Create a
JanetTuple
from a given element and size
use janetrs::{Janet, tuple};
let t = tuple!["123"; 3];
assert_eq!(t[0], &Janet::from("123"));
assert_eq!(t[1], &Janet::from("123"));
assert_eq!(t[2], &Janet::from("123"));
Note that unlike vec!
from the Rust standard library, this macro doesn’t try to
clone the elements passed.
Also note that this macro builds the tuples 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.