From ca44c7878eee56ba59ddfd0ffa09e750e20766d5 Mon Sep 17 00:00:00 2001 From: Matt Bilker Date: Fri, 12 Oct 2018 00:53:13 +0000 Subject: [PATCH] value: add as_str and as_string helper methods --- src/value/mod.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/value/mod.rs b/src/value/mod.rs index 9a8f752..f991894 100644 --- a/src/value/mod.rs +++ b/src/value/mod.rs @@ -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 { + match self { + Value::String(s) => Ok(s), + value => Err(KbinErrorKind::ValueTypeMismatch(StandardType::String, value).into()), + } + } + pub fn as_attribute(self) -> Result { match self { Value::Attribute(s) => Ok(s),