mirror of
https://github.com/mbilker/kbinxml-rs.git
synced 2026-09-09 19:15:27 -05:00
value: add as_str and as_string helper methods
This commit is contained in:
@@ -478,6 +478,20 @@ macro_rules! construct_types {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn as_str(&self) -> Result<&str, KbinError> {
|
||||
match self {
|
||||
Value::String(ref s) => Ok(s),
|
||||
value => Err(KbinErrorKind::ValueTypeMismatch(StandardType::String, value.clone()).into()),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn as_string(self) -> Result<String, KbinError> {
|
||||
match self {
|
||||
Value::String(s) => Ok(s),
|
||||
value => Err(KbinErrorKind::ValueTypeMismatch(StandardType::String, value).into()),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn as_attribute(self) -> Result<String, KbinError> {
|
||||
match self {
|
||||
Value::Attribute(s) => Ok(s),
|
||||
|
||||
Reference in New Issue
Block a user