From 2ee55c09b7708c7aa309d277215ca329dbf131f6 Mon Sep 17 00:00:00 2001 From: Predrag Gruevski Date: Sat, 29 Jul 2023 00:03:44 +0000 Subject: [PATCH] Add `as_arc_str()` and `as_arc_slice()` methods on `FieldValue`. --- trustfall_core/src/ir/value.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/trustfall_core/src/ir/value.rs b/trustfall_core/src/ir/value.rs index b27d7015..478d2a87 100644 --- a/trustfall_core/src/ir/value.rs +++ b/trustfall_core/src/ir/value.rs @@ -176,6 +176,13 @@ impl FieldValue { } } + pub fn as_arc_str(&self) -> Option<&Arc> { + match self { + FieldValue::String(s) => Some(s), + _ => None, + } + } + pub fn as_bool(&self) -> Option { match self { FieldValue::Boolean(b) => Some(*b), @@ -190,6 +197,13 @@ impl FieldValue { } } + pub fn as_arc_slice(&self) -> Option<&Arc<[FieldValue]>> { + match self { + FieldValue::List(l) => Some(l), + _ => None, + } + } + pub fn as_vec_with<'a, T>( &'a self, inner: impl Fn(&'a FieldValue) -> Option,