Struct foxbox_taxonomy::selector::GetterSelector
[−]
[src]
pub struct GetterSelector { pub id: Exactly<Id<Getter>>, pub parent: Exactly<Id<ServiceId>>, pub tags: HashSet<Id<TagId>>, pub service_tags: HashSet<Id<TagId>>, pub kind: Exactly<ChannelKind>, // some fields omitted }
A selector for one or more getter channels.
Example
use foxbox_taxonomy::selector::*; use foxbox_taxonomy::services::*; let selector = GetterSelector::new() .with_parent(Id::new("foxbox")) .with_kind(ChannelKind::CurrentTimeOfDay);
JSON
A selector is an object with the following fields:
- (optional) string
id
: accept only a channel with a given id; - (optional) string
service
: accept only channels of a service with a given id; - (optional) array of string
tags
: accept only channels with all the tags in the array; - (optional) array of string
service_tags
: accept only channels of a service with all the tags in the array; - (optional) string|object
kind
(see ChannelKind): accept only channels of a given kind.
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\", \ \"service\": \"service 1\", \ \"tags\": [\"tag 1\", \"tag 2\"], \ \"service_tags\": [\"tag 3\", \"tag 4\"], \ \"kind\": \"Ready\" \ }"; GetterSelector::from_str(json_selector).unwrap(); // The following will be rejected because no field is provided: let json_empty = "{}"; match GetterSelector::from_str(json_empty) { Err(ParseError::EmptyObject {..}) => { /* as expected */ }, other => panic!("Unexpected result {:?}", other) }
Fields
id | If |
parent | If |
tags | Restrict results to channels that have all the tags in |
service_tags | Restrict results to channels offered by a service that has all the tags in |
kind | If |
Methods
impl GetterSelector
fn new() -> Self
Create a new selector that accepts all getter channels.
fn with_id(self, id: Id<Getter>) -> Self
Restrict to a channel with a specific id.
fn with_parent(self, id: Id<ServiceId>) -> Self
Restrict to a channel with a specific parent.
fn with_kind(self, kind: ChannelKind) -> Self
Restrict to a channel with a specific kind.
fn with_tags(self, tags: Vec<Id<TagId>>) -> Self
Restrict to channels that have all the tags in tags
.
fn with_service_tags(self, tags: Vec<Id<TagId>>) -> Self
Restrict to channels offered by a service that has all the tags in tags
.
fn and(self, other: Self) -> Self
Restrict to channels that are accepted by two selector.
fn matches(&self, service_tags: &HashSet<Id<TagId>>, channel: &Channel<Getter>) -> bool
Determine if a channel is matched by this selector.