Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add as_arc_str() and as_arc_slice() methods on FieldValue. #414

Merged
merged 1 commit into from
Jul 29, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions trustfall_core/src/ir/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,13 @@ impl FieldValue {
}
}

pub fn as_arc_str(&self) -> Option<&Arc<str>> {
match self {
FieldValue::String(s) => Some(s),
_ => None,
}
}

pub fn as_bool(&self) -> Option<bool> {
match self {
FieldValue::Boolean(b) => Some(*b),
Expand All @@ -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<T>,
Expand Down