Skip to content

Commit

Permalink
feat(value): Allow moving into constituent types
Browse files Browse the repository at this point in the history
  • Loading branch information
epage committed Nov 17, 2018
1 parent 32c605b commit bc07812
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions liquid-value/src/values.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,14 @@ impl Value {
}
}

/// Extracts the scalar value if it is a scalar.
pub fn into_scalar(self) -> Option<Scalar> {
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()
Expand All @@ -98,6 +106,14 @@ impl Value {
}
}

/// Extracts the array value if it is an array.
pub fn into_array(self) -> Option<Array> {
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()
Expand All @@ -119,11 +135,27 @@ impl Value {
}
}

/// Extracts the object value if it is a object.
pub fn into_object(self) -> Option<Object> {
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 {
Expand Down

0 comments on commit bc07812

Please sign in to comment.