Function libxivdat::xiv_macro::as_macro [−][src]
pub fn as_macro(bytes: &[u8]) -> Result<MacroData<'_>, DATError>
Expand description
Interprets a byte slice as MacroData
.
Errors
Returns a DATError::Overflow
or DATError::Underflow
if
a macro section has a length that does not match the length specified in its header.
If a macro section does not have valid utf-8 content, a DATError::BadEncoding
error will be returned.
Examples
use libxivdat::dat_file::DATFile; use libxivdat::high_level::AsBytes; use libxivdat::xiv_macro::{as_macro, read_macro}; use libxivdat::xiv_macro::icon::MacroIcon; let mut dat_file = DATFile::open("./resources/TEST_MACRO.DAT").unwrap(); let a_macro = read_macro(&mut dat_file).unwrap(); let macro_bytes = a_macro.as_bytes().unwrap(); let macro_data = as_macro(¯o_bytes).unwrap(); assert_eq!(macro_data.title, "0"); assert_eq!(macro_data.lines[0], "DefaultIcon"); assert_eq!(macro_data.get_icon().unwrap(), MacroIcon::DefaultIcon);