Struct foxbox_taxonomy::selector::ServiceSelector
[−]
[src]
pub struct ServiceSelector { pub id: Exactly<Id<ServiceId>>, pub tags: HashSet<Id<TagId>>, pub getters: Vec<GetterSelector>, pub setters: Vec<SetterSelector>, // some fields omitted }
A selector for one or more services.
Example
use foxbox_taxonomy::selector::*; use foxbox_taxonomy::services::*; let selector = ServiceSelector::new() .with_tags(vec![Id::<TagId>::new("entrance")]) .with_getters(vec![GetterSelector::new() /* can be more restrictive */]);
JSON
A selector is an object with the following fields:
- (optional) string
id
: accept only a service with a given id; - (optional) array of string
tags
: accept only services with all the tags in the array; - (optional) array of objects
getters
(see GetterSelector): accept only services with channels matching all the selectors in this array; - (optional) array of objects
setters
(see SetterSelector): accept only services with channels matching all the selectors in this array;
While each field is optional, at least one field must be provided.
use foxbox_taxonomy::selector::*; // A selector with all fields defined. let json_selector = "{ \"id\": \"setter 1\", \"tags\": [\"tag 1\", \"tag 2\"], \"getters\": [{ \"kind\": \"Ready\" }], \"setters\": [{ \"tags\": [\"tag 3\"] }] }"; ServiceSelector::from_str(json_selector).unwrap(); // The following will be rejected because no field is provided: let json_empty = "{}"; match ServiceSelector::from_str(json_empty) { Err(ParseError::EmptyObject {..}) => { /* as expected */ }, other => panic!("Unexpected result {:?}", other) }
Fields
id | If |
tags | Restrict results to services that have all the tags in |
getters | Restrict results to services that have all the getters in |
setters | Restrict results to services that have all the setters in |
Methods
impl ServiceSelector
fn new() -> Self
Create a new selector that accepts all services.
fn with_id(self, id: Id<ServiceId>) -> Self
Selector for a service with a specific id.
fn with_tags(self, tags: Vec<Id<TagId>>) -> Self
Restrict results to services that have all the tags in tags
.
fn with_getters(self, getters: Vec<GetterSelector>) -> Self
Restrict results to services that have all the getters in getters
.
fn with_setters(self, setters: Vec<SetterSelector>) -> Self
Restrict results to services that have all the setters in setters
.
fn and(self, other: ServiceSelector) -> Self
Restrict results to services that are accepted by two selector.