From 16595bfc1e84f9df63d762b09118fdf18eb24038 Mon Sep 17 00:00:00 2001 From: Mark Rowe Date: Mon, 29 Sep 2025 13:42:35 -0700 Subject: [Rust] Add support for activity eligibility predicates involving platforms --- rust/src/workflow/activity.rs | 47 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) (limited to 'rust/src/workflow') diff --git a/rust/src/workflow/activity.rs b/rust/src/workflow/activity.rs index a893e798..a9afc2f1 100644 --- a/rust/src/workflow/activity.rs +++ b/rust/src/workflow/activity.rs @@ -453,6 +453,52 @@ impl From for Predicate { } } +/// A predicate that checks the platform of the [`BinaryView`](crate::binary_view::BinaryView). +#[must_use] +pub enum Platform { + In(Vec), + NotIn(Vec), +} + +impl Platform { + /// Creates a new predicate that checks if the platform of the [`BinaryView`](crate::binary_view::BinaryView) + /// _is_ in the provided list. + pub fn in_(values: I) -> Self + where + I: IntoIterator, + S: AsRef, + { + Platform::In(values.into_iter().map(|s| s.as_ref().to_string()).collect()) + } + + /// Creates a new predicate that checks if the platform of the [`BinaryView`](crate::binary_view::BinaryView) + /// _is not_ in the provided list. + pub fn not_in(values: I) -> Self + where + I: IntoIterator, + S: AsRef, + { + Platform::NotIn(values.into_iter().map(|s| s.as_ref().to_string()).collect()) + } +} + +impl From for Predicate { + fn from(predicate: Platform) -> Self { + match predicate { + Platform::In(value) => Predicate { + predicate_type: PredicateType::Platform, + operator: Operator::In, + value: serde_json::json!(value), + }, + Platform::NotIn(value) => Predicate { + predicate_type: PredicateType::Platform, + operator: Operator::NotIn, + value: serde_json::json!(value), + }, + } + } +} + /// A predicate that evaluates the value of a specific setting. #[must_use] pub struct Setting { @@ -533,6 +579,7 @@ impl From for Predicate { enum PredicateType { Setting { identifier: String }, ViewType, + Platform, } #[derive(Deserialize, Serialize, Debug, Copy, Clone)] -- cgit v1.3.1