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:

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 Exactly(id), return only the channel with the corresponding id.

parent

If Eactly(id), return only channels that are children of service id.

tags

Restrict results to channels that have all the tags in tags.

service_tags

Restrict results to channels offered by a service that has all the tags in tags.

kind

If Exatly(k), restrict results to channels that produce values of kind k.

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.

Trait Implementations

impl Deserialize for GetterSelector

fn deserialize<__D>(deserializer: &mut __D) -> Result<GetterSelector, __D::Error> where __D: Deserializer

impl Parser<GetterSelector> for GetterSelector

fn description() -> String

fn parse(path: Path, source: &mut JSON) -> Result<Self, ParseError>

fn from_str(source: &str) -> Result<T, ParseError>

fn take(path: Path, source: &mut JSON, field_name: &str) -> Result<T, ParseError>

fn take_opt(path: Path, source: &mut JSON, field_name: &str) -> Option<Result<T, ParseError>>

fn take_vec_opt(path: Path, source: &mut JSON, field_name: &str) -> Option<Result<Vec<T>, ParseError>>

fn take_vec(path: Path, source: &mut JSON, field_name: &str) -> Result<Vec<T>, ParseError>

Derived Implementations

impl Default for GetterSelector

fn default() -> GetterSelector

impl Debug for GetterSelector

fn fmt(&self, __arg_0: &mut Formatter) -> Result

impl Clone for GetterSelector

fn clone(&self) -> GetterSelector

1.0.0fn clone_from(&mut self, source: &Self)