value: add as_str and as_string helper methods

This commit is contained in:
Matt Bilker
2018-10-12 00:53:13 +00:00
parent 235f9fe2ae
commit ca44c7878e

View File

@@ -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),