starlane 0.3.21

Starlane -- An Orchestration and Infrastructure Framework for WebAssembly Components (https://starlane.io) This packaged manages `HyperSpace` which provides infrastructure for `Space` Apis (WebAssembly & external programs meant to provide custom behaviors in Starlane), This package references the `starlane-space` package and reuses of it to run the infrastructure and it also contains mechanisms (Drivers) for extending the Starlane Type system
Documentation
use crate::hyperspace::service::{ServiceSelector, ServiceTemplate};
use itertools::Itertools;
use crate::space::selector::KindSelector;
use std::marker::PhantomData;
use std::ops::{Deref, DerefMut};

#[derive(Clone)]
pub struct Templates<T>
where
    T: Clone,
{
    templates: Vec<T>,
}

impl<T> Templates<T>
where
    T: Clone,
{
    pub fn new(templates: Vec<T>) -> Self {
        Self { templates }
    }

    pub fn select_one<S>(&self, selector: &S) -> Option<&T>
    where
        S: PartialEq<T>,
    {
        (&self.templates)
            .into_iter()
            .find_position(|t| *selector == **t)
            .map(|(size, t)| t)
    }
}

impl Templates<ServiceTemplate> {
    pub fn select(&self, selector: &ServiceSelector) -> Vec<ServiceTemplate> {
        todo!()
        //let mut rtn = vec![];
        /*        for template in &self.templates {
                   if selector.matches(&template.kind) {
                       rtn.push(template.clone());
                   }
               }
               rtn

        */
    }

    /*
    /// return the first match found
    pub fn select_one(&self, selector: &ServiceSelector) -> Option<ServiceTemplate> {
        self.select(selector).first().cloned()
    }

     */
}

impl<T> Default for Templates<T>
where
    T: Clone,
{
    fn default() -> Self {
        Self {
            templates: Vec::default(),
        }
    }
}

impl Deref for Templates<ServiceTemplate> {
    type Target = Vec<ServiceTemplate>;

    fn deref(&self) -> &Self::Target {
        &self.templates
    }
}

impl DerefMut for Templates<ServiceTemplate> {
    fn deref_mut(&mut self) -> &mut Self::Target {
        &mut self.templates
    }
}