Function nbt::decode_named[][src]

pub fn decode_named<T: DeserializeOwned>(
    tag: Blob
) -> Result<(String, T), NBTError>

Decode a NBT Blob into a Serde deserializable value and the given root name.

Example

use nbt::{Tag, Blob, decode_named};
use serde::Deserialize;

// Create Deserializable struct
#[derive(Deserialize, PartialEq, Debug)]
pub struct Example {
    foo: String
}

// Create a Blob
let mut blob = Blob::create("baz");
blob.insert("foo", "bar");

// Decode the root name and data from blob
let (root, data): (String, Example) = decode_named(blob).unwrap();

assert_eq!(data, Example { foo: "bar".to_string() });
assert_eq!(root, "baz".to_string());