diff --git a/Cargo.toml b/Cargo.toml index ea445b7..0f28a9a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "kbinxml" -version = "0.13.2" +version = "0.13.3" authors = ["Matt Bilker "] [dependencies] diff --git a/src/value/mod.rs b/src/value/mod.rs index f991894..54351e7 100644 --- a/src/value/mod.rs +++ b/src/value/mod.rs @@ -478,6 +478,13 @@ macro_rules! construct_types { } } + pub fn as_slice(&self) -> Result<&[u8], KbinError> { + match self { + Value::Binary(ref data) => Ok(data), + value => Err(KbinErrorKind::ValueTypeMismatch(StandardType::Binary, value.clone()).into()), + } + } + pub fn as_str(&self) -> Result<&str, KbinError> { match self { Value::String(ref s) => Ok(s), @@ -498,6 +505,13 @@ macro_rules! construct_types { value => Err(KbinErrorKind::ValueTypeMismatch(StandardType::Attribute, value).into()), } } + + pub fn as_array(&self) -> Result<&[Value], KbinError> { + match self { + Value::Array(_, ref values) => Ok(values), + value => Err(KbinErrorKind::ExpectedValueArray(value.clone()).into()), + } + } } #[cfg(feature = "serde")]