Macro janetrs::array

source ·
macro_rules! array {
    () => { ... };
    ($elem:expr; $n:expr) => { ... };
    ($($val:expr),* $(,)?) => { ... };
}
Expand description

Creates a JanetArray containing the arguments.

tuple! allows JanetArrays to be defined with the same syntax as Rust array expressions. There are 2 forms of this macro:

  • Create a JanetArray containing a given list of elements
use janetrs::{array, Janet};

let arr = array![3, true, "hey"];

assert_eq!(arr[0], &Janet::integer(3));
assert_eq!(arr[1], &Janet::boolean(true));
assert_eq!(arr[2], &Janet::from("hey"));
  • Create a JanetArray from a given element and size
use janetrs::{Janet, array};

let arr = array!["123"; 3];

assert_eq!(arr[0], &Janet::from("123"));
assert_eq!(arr[1], &Janet::from("123"));
assert_eq!(arr[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 array 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.