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:

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

tags

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

getters

Restrict results to services that have all the getters in getters.

setters

Restrict results to services that have all the setters in setters.

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.

fn matches<T>(&self, service: &T) -> bool where T: ServiceLike

Trait Implementations

impl Deserialize for ServiceSelector

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

impl Parser<ServiceSelector> for ServiceSelector

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 ServiceSelector

fn default() -> ServiceSelector

impl Debug for ServiceSelector

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

impl Clone for ServiceSelector

fn clone(&self) -> ServiceSelector

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