mirror of
https://github.com/mbilker/kbinxml-rs.git
synced 2026-09-09 19:15:27 -05:00
value: add as_slice and as_array helper conversion methods
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "kbinxml"
|
||||
version = "0.13.2"
|
||||
version = "0.13.3"
|
||||
authors = ["Matt Bilker <me@mbilker.us>"]
|
||||
|
||||
[dependencies]
|
||||
|
||||
@@ -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")]
|
||||
|
||||
Reference in New Issue
Block a user