Function nbt::encode[][src]

pub fn encode<T: Serialize>(o: &T) -> Result<Blob, NBTError>

Encode a Serde serializable value into a NBT Blob with a empty root name.

Encode a Serde serializable value into a NBT Blob with a given root name. Encode a Serde serializable value into a NBT Blob with a given root name.

Example

use nbt::{encode_tag, encode, Tag};
use std::collections::HashMap;
use serde::Serialize;

// Define a Serializable Struct
#[derive(Serialize)]
pub struct Example {
    foo: String,
    bar: i8,
    baz: i16
}

// Create a instance
let example = Example {
    foo: "Hello World!".to_string(),
    bar: 42,
    baz: 25565
};
// Encode a NBT blob with name "example"
let tag = encode(&example).unwrap();