diff --git a/liquid-value/src/values.rs b/liquid-value/src/values.rs index 57c783737..877e68141 100644 --- a/liquid-value/src/values.rs +++ b/liquid-value/src/values.rs @@ -77,6 +77,14 @@ impl Value { } } + /// Extracts the scalar value if it is a scalar. + pub fn into_scalar(self) -> Option { + match self { + Value::Scalar(s) => Some(s), + _ => None, + } + } + /// Tests whether this value is a scalar pub fn is_scalar(&self) -> bool { self.as_scalar().is_some() @@ -98,6 +106,14 @@ impl Value { } } + /// Extracts the array value if it is an array. + pub fn into_array(self) -> Option { + match self { + Value::Array(s) => Some(s), + _ => None, + } + } + /// Tests whether this value is an array pub fn is_array(&self) -> bool { self.as_array().is_some() @@ -119,11 +135,27 @@ impl Value { } } + /// Extracts the object value if it is a object. + pub fn into_object(self) -> Option { + match self { + Value::Object(s) => Some(s), + _ => None, + } + } + /// Tests whether this value is an object pub fn is_object(&self) -> bool { self.as_object().is_some() } + /// Extracts the nil value if it is nil + pub fn as_nil(&self) -> Option<()> { + match *self { + Value::Nil => Some(()), + _ => None, + } + } + /// Tests whether this value is nil pub fn is_nil(&self) -> bool { match *self {