macro_rules! compound { (<$string_type:ty> $($key:expr => $value:expr),* $(,)?) => { ... }; ($($key:expr => $value:expr),* $(,)?) => { ... }; }
Expand description
A convenience macro for constructing Compound
s.
Key expressions must implement Into<String>
while value expressions must
implement Into<Value>
.
§Examples
use valence_nbt::{compound, List};
let c = compound! {
"byte" => 123_i8,
"list_of_int" => List::Int(vec![3, -7, 5]),
"list_of_string" => List::String(vec![
"foo".to_owned(),
"bar".to_owned(),
"baz".to_owned()
]),
"string" => "aé日",
"compound" => compound! {
"foo" => 1,
"bar" => 2,
"baz" => 3,
},
"int_array" => vec![5, -9, i32::MIN, 0, i32::MAX],
"byte_array" => vec![0_i8, 2, 3],
"long_array" => vec![123_i64, 456, 789],
};
println!("{c:?}");
It is also possible to specify a custom string type like this:
use valence_nbt::compound;
let c = compound! { <Cow<str>>
"foo" => 123_i8,
};
println!("{c:?}");