[][src]Function nbt::ser::i32_array

pub fn i32_array<T, S>(array: T, serializer: S) -> Result<S::Ok, S::Error> where
    T: IntoIterator,
    <T as IntoIterator>::Item: Borrow<i32>,
    S: Serializer

This function provides serde serialization support for NBT type IntArray.

It should be used in conjunction with serde's field annotation serialize_with. In the following example int_data will be serialized as an IntArray instead of a List of Ints:

extern crate serde;
use nbt::to_writer;
use serde::Serialize;

let mut serialized = Vec::new();

// Declare your struct
#[derive(Serialize)]
struct Cow {
    #[serde(serialize_with="nbt::i32_array")]
    int_data: Vec<i32>,
}

// Serialize to NBT!
to_writer(
    &mut serialized,
    &Cow {
        int_data: vec![1, 8, 64, 512, 4096, 32768, 262144],
    },
    None
).unwrap();

print!("Serialized: {:?}", serialized);