Enum roead::byml::Byml

source ·
pub enum Byml {
Show 15 variants String(String), BinaryData(Vec<u8>), FileData(Vec<u8>), Array(Vec<Byml>), Map(Map), HashMap(HashMap), ValueHashMap(ValueHashMap), Bool(bool), I32(i32), Float(f32), U32(u32), I64(i64), U64(u64), Double(f64), Null,
}
Expand description

Represents a Nintendo binary YAML (BYML) document or node.

Variants§

§

String(String)

String value.

§

BinaryData(Vec<u8>)

Binary data (not used in BOTW).

§

FileData(Vec<u8>)

File data

§

Array(Vec<Byml>)

Array of BYML nodes.

§

Map(Map)

Hash map of BYML nodes with string keys.

§

HashMap(HashMap)

Hash map of BYML nodes with u32 keys.

§

ValueHashMap(ValueHashMap)

Hash map of BYML nodes with u32 keys and additional value.

§

Bool(bool)

Boolean value.

§

I32(i32)

32-bit signed integer.

§

Float(f32)

32-bit float.

§

U32(u32)

32-bit unsigned integer.

§

I64(i64)

64-bit signed integer.

§

U64(u64)

64-bit unsigned integer.

§

Double(f64)

64-bit float.

§

Null

Null value.

Implementations§

source§

impl Byml

source

pub fn from_text(text: impl AsRef<str>) -> Result<Byml>

Parse BYML document from YAML text.

source

pub fn to_text(&self) -> String

Serialize the document to YAML. This can only be done for Null, Array, or Hash nodes.

source§

impl Byml

source

pub fn write<W: Write + Seek>( &self, writer: &mut W, endian: Endian, version: u16 ) -> Result<()>

Serialize the document to binary into the given writer. This can only be done for Null, Array, or Hash nodes.

source

pub fn to_binary(&self, endian: Endian) -> Vec<u8>

Serialize the document to bytes with the specified endianness and default version (2). This can only be done for Null, Array, or Hash nodes.

source

pub fn to_binary_with_version(&self, endian: Endian, version: u16) -> Vec<u8>

Serialize the document to BYML with the specified endianness and version number. This can only be done for Null, Array, or Hash nodes.

source§

impl Byml

source

pub fn read<R: Read + Seek>(reader: R) -> Result<Byml>

Read a document from a binary reader.

source

pub fn from_binary(data: impl AsRef<[u8]>) -> Result<Byml>

Load a document from binary data.

Note: If and only if the yaz0 feature is enabled, this function automatically decompresses the SARC when necessary.

source§

impl Byml

source

pub fn is_null(&self) -> bool

Checks if the BYML node is a null node

source

pub fn as_bool(&self) -> Result<bool>

Get a reference to the inner bool value.

source

pub fn as_i32(&self) -> Result<i32>

Get a reference to the inner i32 value.

source

pub fn as_u32(&self) -> Result<u32>

Get a reference to the inner u32 value.

source

pub fn as_i64(&self) -> Result<i64>

Get a reference to the inner i64 value.

source

pub fn as_u64(&self) -> Result<u64>

Get a reference to the inner u64 value.

source

pub fn as_int<T>(&self) -> Result<T>
where T: Copy + 'static, i32: AsPrimitive<T>, u32: AsPrimitive<T>, i64: AsPrimitive<T>, u64: AsPrimitive<T>,

Get the inner value as an integer of any type. Casts the value using as where necessary. Note that this is subject to all the normal risks of casting with as.

source

pub fn as_num<T>(&self) -> Result<T>
where T: Copy + 'static, i32: AsPrimitive<T>, u32: AsPrimitive<T>, i64: AsPrimitive<T>, u64: AsPrimitive<T>, f32: AsPrimitive<T>, f64: AsPrimitive<T>,

Get the inner value as a number of any type. Casts the value using as where necessary. Note that this is subject to all the normal risks of casting with as.

source

pub fn as_float(&self) -> Result<f32>

Get a reference to the inner f32 value.

source

pub fn as_double(&self) -> Result<f64>

Get a reference to the inner f64 value.

source

pub fn as_string(&self) -> Result<&String>

Get a reference to the inner string value.

source

pub fn as_binary_data(&self) -> Result<&[u8]>

Get a reference to the inner byte slice.

source

pub fn as_array(&self) -> Result<&[Byml]>

Get a reference to the inner array of BYML nodes.

source

pub fn as_map(&self) -> Result<&Map>

Get a reference to the inner string-keyed hash map of BYML nodes.

source

pub fn as_hash_map(&self) -> Result<&HashMap>

Get a reference to the inner u32-keyed hash map of BYML nodes.

source

pub fn as_value_hash_map(&self) -> Result<&ValueHashMap>

Get a reference to the inner u32-keyed hash map of BYML nodes.

source

pub fn as_mut_string(&mut self) -> Result<&mut String>

Get a mutable reference to the inner string value.

source

pub fn as_mut_bool(&mut self) -> Result<&mut bool>

Get a mutable reference to the inner bool value.

source

pub fn as_mut_i32(&mut self) -> Result<&mut i32>

Get a mutable reference to the inner i32 value.

source

pub fn as_mut_u32(&mut self) -> Result<&mut u32>

Get a mutable reference to the inner u32 value.

source

pub fn as_mut_i64(&mut self) -> Result<&mut i64>

Get a mutable reference to the inner i64 value.

source

pub fn as_mut_u64(&mut self) -> Result<&mut u64>

Get a mutable reference to the inner u64 value.

source

pub fn as_mut_float(&mut self) -> Result<&mut f32>

Get a mutable reference to the inner f32 value.

source

pub fn as_mut_double(&mut self) -> Result<&mut f64>

Get a mutable reference to the inner f64 value.

source

pub fn as_mut_binary_data(&mut self) -> Result<&mut [u8]>

Get a mutable reference to the inner byte slice.

source

pub fn as_mut_array(&mut self) -> Result<&mut Vec<Byml>>

Get a mutable reference to the inner array of BYML nodes.

source

pub fn as_mut_map(&mut self) -> Result<&mut Map>

Get a mutable reference to the inner hash map of BYML nodes.

source

pub fn as_mut_hash_map(&mut self) -> Result<&mut HashMap>

Get a reference to the inner u32-keyed hash map of BYML nodes.

source

pub fn as_mut_value_hash_map(&mut self) -> Result<&mut ValueHashMap>

Get a reference to the inner u32-keyed hash map of BYML nodes.

source

pub fn into_string(self) -> Result<String>

Extract the inner string value.

source

pub fn into_bool(self) -> Result<bool>

Extract the inner bool value.

source

pub fn into_i32(self) -> Result<i32>

Extract the inner i32 value.

source

pub fn into_u32(self) -> Result<u32>

Extract the inner u32 value.

source

pub fn into_i64(self) -> Result<i64>

Extract the inner i64 value.

source

pub fn into_u64(self) -> Result<u64>

Extract the inner u64 value.

source

pub fn into_float(self) -> Result<f32>

Extract the inner f32 value.

source

pub fn into_double(self) -> Result<f64>

Extract the inner f64 value.

source

pub fn into_binary_data(self) -> Result<Vec<u8>>

Extract the inner byte slice value.

source

pub fn into_array(self) -> Result<Vec<Byml>>

Extract the inner Byml array value.

source

pub fn into_map(self) -> Result<Map>

Extract the inner map value.

source

pub fn into_hash_map(self) -> Result<HashMap>

Extract the inner hash map value.

source

pub fn into_value_hash_map(self) -> Result<ValueHashMap>

Extract the inner value hash map value.

Trait Implementations§

source§

impl Clone for Byml

source§

fn clone(&self) -> Byml

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Byml

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for Byml

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl<'de> Deserialize<'de> for Byml

source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl From<&[Byml]> for Byml

source§

fn from(value: &[Byml]) -> Self

Converts to this type from the input type.
source§

impl From<&SmartString<LazyCompact>> for Byml

source§

fn from(value: &String) -> Self

Converts to this type from the input type.
source§

impl From<&String> for Byml

source§

fn from(value: &String) -> Self

Converts to this type from the input type.
source§

impl From<&str> for Byml

source§

fn from(value: &str) -> Self

Converts to this type from the input type.
source§

impl From<HashMap<SmartString<LazyCompact>, Byml, BuildHasherDefault<FxHasher>>> for Byml

source§

fn from(value: Map) -> Self

Converts to this type from the input type.
source§

impl From<HashMap<u32, (Byml, u32), BuildHasherDefault<FxHasher>>> for Byml

source§

fn from(value: ValueHashMap) -> Self

Converts to this type from the input type.
source§

impl From<HashMap<u32, Byml, BuildHasherDefault<FxHasher>>> for Byml

source§

fn from(value: HashMap) -> Self

Converts to this type from the input type.
source§

impl From<SmartString<LazyCompact>> for Byml

source§

fn from(value: String) -> Self

Converts to this type from the input type.
source§

impl From<String> for Byml

source§

fn from(value: String) -> Self

Converts to this type from the input type.
source§

impl From<Vec<Byml>> for Byml

source§

fn from(value: Vec<Byml>) -> Self

Converts to this type from the input type.
source§

impl From<bool> for Byml

source§

fn from(value: bool) -> Self

Converts to this type from the input type.
source§

impl From<f32> for Byml

source§

fn from(value: f32) -> Self

Converts to this type from the input type.
source§

impl From<f64> for Byml

source§

fn from(value: f64) -> Self

Converts to this type from the input type.
source§

impl From<i32> for Byml

source§

fn from(value: i32) -> Self

Converts to this type from the input type.
source§

impl From<i64> for Byml

source§

fn from(value: i64) -> Self

Converts to this type from the input type.
source§

impl From<u32> for Byml

source§

fn from(value: u32) -> Self

Converts to this type from the input type.
source§

impl From<u64> for Byml

source§

fn from(value: u64) -> Self

Converts to this type from the input type.
source§

impl<S: Into<String>> FromIterator<(S, Byml)> for Byml

source§

fn from_iter<T: IntoIterator<Item = (S, Byml)>>(iter: T) -> Self

Creates a value from an iterator. Read more
source§

impl FromIterator<Byml> for Byml

source§

fn from_iter<T: IntoIterator<Item = Byml>>(iter: T) -> Self

Creates a value from an iterator. Read more
source§

impl Hash for Byml

source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl<'a, I: Into<BymlIndex<'a>>> Index<I> for Byml

§

type Output = Byml

The returned type after indexing.
source§

fn index(&self, index: I) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
source§

impl<'a, I: Into<BymlIndex<'a>>> IndexMut<I> for Byml

source§

fn index_mut(&mut self, index: I) -> &mut Self::Output

Performs the mutable indexing (container[index]) operation. Read more
source§

impl PartialEq<Byml> for &Byml

source§

fn eq(&self, other: &Byml) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialEq for Byml

source§

fn eq(&self, other: &Self) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Serialize for Byml

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl TryFrom<Byml> for Map

§

type Error = Byml

The type returned in the event of a conversion error.
source§

fn try_from(value: Byml) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<Byml> for ValueHashMap

§

type Error = Byml

The type returned in the event of a conversion error.
source§

fn try_from(value: Byml) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<Byml> for HashMap

§

type Error = Byml

The type returned in the event of a conversion error.
source§

fn try_from(value: Byml) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<Byml> for String

§

type Error = Byml

The type returned in the event of a conversion error.
source§

fn try_from(value: Byml) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<Byml> for Vec<Byml>

§

type Error = Byml

The type returned in the event of a conversion error.
source§

fn try_from(value: Byml) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<Byml> for Vec<u8>

§

type Error = Byml

The type returned in the event of a conversion error.
source§

fn try_from(value: Byml) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<Byml> for bool

§

type Error = Byml

The type returned in the event of a conversion error.
source§

fn try_from(value: Byml) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<Byml> for f32

§

type Error = Byml

The type returned in the event of a conversion error.
source§

fn try_from(value: Byml) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<Byml> for f64

§

type Error = Byml

The type returned in the event of a conversion error.
source§

fn try_from(value: Byml) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<Byml> for i32

§

type Error = Byml

The type returned in the event of a conversion error.
source§

fn try_from(value: Byml) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<Byml> for i64

§

type Error = Byml

The type returned in the event of a conversion error.
source§

fn try_from(value: Byml) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<Byml> for u32

§

type Error = Byml

The type returned in the event of a conversion error.
source§

fn try_from(value: Byml) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<Byml> for u64

§

type Error = Byml

The type returned in the event of a conversion error.
source§

fn try_from(value: Byml) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl Eq for &Byml

Auto Trait Implementations§

§

impl Freeze for Byml

§

impl RefUnwindSafe for Byml

§

impl Send for Byml

§

impl Sync for Byml

§

impl Unpin for Byml

§

impl UnwindSafe for Byml

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,