microversus_codex 0.1.6

Types and definitions for interfacing with the microversus system
Documentation
use serde::{Deserialize, Serialize};

#[derive(Debug, Serialize, Deserialize)]
#[serde(tag = "_tag")]
pub enum TraitValue {
    #[serde(rename = "exactly")]
    Exactly { value: String },
    #[serde(rename = "any-of")]
    AnyOf { values: Vec<String> },
    #[serde(rename = "like")]
    Like { pattern: String },
}

#[derive(Debug, Serialize, Deserialize)]
pub struct TraitRequirement {
    pub key: String,
    pub value: TraitValue,
}

#[derive(Debug, Serialize, Deserialize)]
#[serde(tag = "_tag")]
pub enum Matcher {
    #[serde(rename = "loose")]
    Loose {},

    #[serde(rename = "matching-policy")]
    MatchingPolicy { policies: Vec<String> },

    #[serde(rename = "matching-name")]
    MatchingName { like: String },

    #[serde(rename = "matching-traits")]
    MatchingTraits {
        policies: Vec<String>,
        traits: Vec<TraitRequirement>,
    },

    #[serde(rename = "not")]
    Not { matcher: Box<Matcher> },

    #[serde(rename = "all")]
    All { matchers: Vec<Matcher> },

    #[serde(rename = "any")]
    Any { matchers: Vec<Matcher> },
}

#[derive(Debug, Serialize, Deserialize, PartialEq)]
#[serde(rename_all = "lowercase")]
pub enum TribeSlotPrivilege {
    Control,
    Create,
}

#[derive(Debug, Serialize, Deserialize)]
pub struct TribeSlot {
    pub id: String,
    pub count: usize,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub label: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub privileges: Option<Vec<TribeSlotPrivilege>>,
    pub matcher: Matcher,
}

#[derive(Debug, Serialize, Deserialize)]
pub struct Tribe {
    pub key: String,
    pub name: String,
    pub slots: Vec<TribeSlot>,
}