pub enum Byml {
Null,
String(String),
Binary(Vec<u8>),
Array(Vec<Byml>),
Hash(BTreeMap<String, Byml>),
Bool(bool),
Int(i32),
Float(Float),
UInt(u32),
Int64(i64),
UInt64(u64),
Double(Double),
}Expand description
Represents a Nintendo binary YAML (BYML) document or node. A Byml will usually be constructed
from binary data or a YAML string, e.g.
let buf: Vec<u8> = std::fs::read("A-1_Static.smubin")?;
let map_unit = Byml::from_binary(&buf)?;
let text: String = std::fs::read_to_string("A-1_Static.yml")?;
let map_unit2 = Byml::from_text(&text)?;
assert_eq!(map_unit, map_unit2);You can also easily serialize to binary or a YAML string.
let buf: Vec<u8> = std::fs::read("A-1_Static.smubin")?;
let map_unit = Byml::from_binary(&buf)?;
std::fs::write("A-1_Static.yml", &map_unit.to_text()?)?;
std::fs::write("A-1_Static.copy.mubin", &map_unit.to_binary(Endian::Big, 2)?)?;A number of convenience getters are available which return a result for a variant value:
let doc = Byml::from_binary(&some_data)?;
let hash: &BTreeMap<String, Byml> = doc.as_hash()?;Most of the node types are fairly self-explanatory. Arrays are implemented as Vec<Byml>, and
hash nodes as BTreeMap<String, Byml>. Floats (f32) and doubles (f64) use wrapper types that
support Eq. These can be converted with into(). You can also query the node type with
get_type().
For convenience, a Byml known to be an array or hash node can be indexed. Panics if the
node has the wrong type or if the index is not found.
let buf: Vec<u8> = std::fs::read("ActorInfo.product.sbyml")?;
let actor_info = Byml::from_binary(&buf)?;
assert_eq!(actor_info["Actors"].as_array()?.len(), 7934);
assert_eq!(actor_info["Hashes"][0].as_int()?, 31119);Variants§
Null
String(String)
Binary(Vec<u8>)
Array(Vec<Byml>)
Hash(BTreeMap<String, Byml>)
Bool(bool)
Int(i32)
Float(Float)
UInt(u32)
Int64(i64)
UInt64(u64)
Double(Double)
Implementations§
Source§impl Byml
impl Byml
Sourcepub fn to_binary(
&self,
endian: Endian,
version: u16,
) -> Result<Vec<u8>, WriteError>
pub fn to_binary( &self, endian: Endian, version: u16, ) -> Result<Vec<u8>, WriteError>
Serialize the document to binary data with the specified endianness and version. Only hash, array, or null nodes can be used.
Source§impl Byml
impl Byml
Sourcepub fn is_container(&self) -> bool
pub fn is_container(&self) -> bool
Returns whether the node is an array or hash
Sourcepub fn is_value(&self) -> bool
pub fn is_value(&self) -> bool
Returns whether the node is an inline value (Int, UInt, Float, or Bool)
Sourcepub fn as_hash(&self) -> Result<&BTreeMap<String, Byml>, TypeError>
pub fn as_hash(&self) -> Result<&BTreeMap<String, Byml>, TypeError>
Returns a result with a reference to the inner BYML hash or a type error
Sourcepub fn as_array(&self) -> Result<&Vec<Byml>, TypeError>
pub fn as_array(&self) -> Result<&Vec<Byml>, TypeError>
Returns a result with a reference to the inner BYML array or a type error
Sourcepub fn as_binary(&self) -> Result<&Vec<u8>, TypeError>
pub fn as_binary(&self) -> Result<&Vec<u8>, TypeError>
Returns a result with a reference to the inner BYML binary data or a type error
Sourcepub fn as_bool(&self) -> Result<bool, TypeError>
pub fn as_bool(&self) -> Result<bool, TypeError>
Returns a result with the inner boolean value or a type error
Sourcepub fn as_string(&self) -> Result<&String, TypeError>
pub fn as_string(&self) -> Result<&String, TypeError>
Returns a result with a reference to the inner string or a type error
Sourcepub fn as_int(&self) -> Result<i32, TypeError>
pub fn as_int(&self) -> Result<i32, TypeError>
Returns a result with the inner i32 value or a type error
Sourcepub fn as_int64(&self) -> Result<i64, TypeError>
pub fn as_int64(&self) -> Result<i64, TypeError>
Returns a result with the inner i64 value or a type error
Sourcepub fn as_uint(&self) -> Result<u32, TypeError>
pub fn as_uint(&self) -> Result<u32, TypeError>
Returns a result with the inner u32 value or a type error
Sourcepub fn as_uint64(&self) -> Result<u64, TypeError>
pub fn as_uint64(&self) -> Result<u64, TypeError>
Returns a result with the inner u64 value or a type error
Sourcepub fn as_float(&self) -> Result<f32, TypeError>
pub fn as_float(&self) -> Result<f32, TypeError>
Returns a result with the inner f32 value or a type error
Sourcepub fn as_double(&self) -> Result<f64, TypeError>
pub fn as_double(&self) -> Result<f64, TypeError>
Returns a result with the inner f64 value or a type error
Sourcepub fn as_mut_hash(&mut self) -> Result<&mut BTreeMap<String, Byml>, TypeError>
pub fn as_mut_hash(&mut self) -> Result<&mut BTreeMap<String, Byml>, TypeError>
Returns a result with a mutable reference to the inner BYML hash or a type error
Sourcepub fn as_mut_array(&mut self) -> Result<&mut Vec<Byml>, TypeError>
pub fn as_mut_array(&mut self) -> Result<&mut Vec<Byml>, TypeError>
Returns a result with a mutable reference to the inner BYML array or a type error
Sourcepub fn as_mut_binary(&mut self) -> Result<&mut Vec<u8>, TypeError>
pub fn as_mut_binary(&mut self) -> Result<&mut Vec<u8>, TypeError>
Returns a result with a mutable reference to the inner binary data or a type error
Sourcepub fn as_mut_string(&mut self) -> Result<&mut String, TypeError>
pub fn as_mut_string(&mut self) -> Result<&mut String, TypeError>
Returns a result with a mutable reference to the inner string or a type error
Sourcepub fn as_mut_int(&mut self) -> Result<&mut i32, TypeError>
pub fn as_mut_int(&mut self) -> Result<&mut i32, TypeError>
Returns a result with a mutable reference to the inner i32 or a type error
Sourcepub fn as_mut_int64(&mut self) -> Result<&mut i64, TypeError>
pub fn as_mut_int64(&mut self) -> Result<&mut i64, TypeError>
Returns a result with a mutable reference to the inner i64 or a type error
Sourcepub fn as_mut_uint(&mut self) -> Result<&mut u32, TypeError>
pub fn as_mut_uint(&mut self) -> Result<&mut u32, TypeError>
Returns a result with a mutable reference to the inner u32 or a type error
Sourcepub fn as_mut_uint64(&mut self) -> Result<&mut u64, TypeError>
pub fn as_mut_uint64(&mut self) -> Result<&mut u64, TypeError>
Returns a result with a mutable reference to the inner u64 or a type error
Trait Implementations§
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more