@@ -453,6 +453,52 @@ impl From<ViewType> for Predicate {
453453 }
454454}
455455
456+ /// A predicate that checks the platform of the [`BinaryView`](crate::binary_view::BinaryView).
457+ #[ must_use]
458+ pub enum Platform {
459+ In ( Vec < String > ) ,
460+ NotIn ( Vec < String > ) ,
461+ }
462+
463+ impl Platform {
464+ /// Creates a new predicate that checks if the platform of the [`BinaryView`](crate::binary_view::BinaryView)
465+ /// _is_ in the provided list.
466+ pub fn in_ < I , S > ( values : I ) -> Self
467+ where
468+ I : IntoIterator < Item = S > ,
469+ S : AsRef < str > ,
470+ {
471+ Platform :: In ( values. into_iter ( ) . map ( |s| s. as_ref ( ) . to_string ( ) ) . collect ( ) )
472+ }
473+
474+ /// Creates a new predicate that checks if the platform of the [`BinaryView`](crate::binary_view::BinaryView)
475+ /// _is not_ in the provided list.
476+ pub fn not_in < I , S > ( values : I ) -> Self
477+ where
478+ I : IntoIterator < Item = S > ,
479+ S : AsRef < str > ,
480+ {
481+ Platform :: NotIn ( values. into_iter ( ) . map ( |s| s. as_ref ( ) . to_string ( ) ) . collect ( ) )
482+ }
483+ }
484+
485+ impl From < Platform > for Predicate {
486+ fn from ( predicate : Platform ) -> Self {
487+ match predicate {
488+ Platform :: In ( value) => Predicate {
489+ predicate_type : PredicateType :: Platform ,
490+ operator : Operator :: In ,
491+ value : serde_json:: json!( value) ,
492+ } ,
493+ Platform :: NotIn ( value) => Predicate {
494+ predicate_type : PredicateType :: Platform ,
495+ operator : Operator :: NotIn ,
496+ value : serde_json:: json!( value) ,
497+ } ,
498+ }
499+ }
500+ }
501+
456502/// A predicate that evaluates the value of a specific setting.
457503#[ must_use]
458504pub struct Setting {
@@ -533,6 +579,7 @@ impl From<Setting> for Predicate {
533579enum PredicateType {
534580 Setting { identifier : String } ,
535581 ViewType ,
582+ Platform ,
536583}
537584
538585#[ derive( Deserialize , Serialize , Debug , Copy , Clone ) ]
0 commit comments