dce-router 1.8.0

A router for all type programming api route.
Documentation
use std::ops::{Deref, DerefMut};

use crate::{api::Api, protocol::RoutableProtocol};

pub struct Context<Rp: RoutableProtocol + 'static> {
    rp: Rp,
    api: Option<&'static Api<Rp>>,
}

impl <Rp: RoutableProtocol> Context<Rp> {
    pub fn new(rp: Rp, api: Option<&'static Api<Rp>>) -> Self {
        Self { rp, api }
    }

    pub fn api(&self) -> &Option<&'static Api<Rp>> {
        &self.api
    }

    pub fn into_rp(self) -> Rp {
        self.rp
    }
}

impl<Rp: RoutableProtocol> Deref for Context<Rp> {
    type Target = Rp;

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

impl <Rp: RoutableProtocol> DerefMut for Context<Rp> {
    fn deref_mut(&mut self) -> &mut Self::Target {
        &mut self.rp
    }
}

pub struct Request<'a, Rp: RoutableProtocol + 'static> {
    ctx: &'a mut Context<Rp>,
}

impl <'a, Rp: RoutableProtocol> Request<'a, Rp> {
    pub fn new(ctx: &'a mut Context<Rp>) -> Self {
        Self { ctx }
    }
}

impl<'a, Rp: RoutableProtocol> Deref for Request<'a, Rp> {
    type Target = Context<Rp>;

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

impl <'a, Rp: RoutableProtocol> DerefMut for Request<'a, Rp> {
    fn deref_mut(&mut self) -> &mut Self::Target {
        &mut self.ctx
    }
}

pub enum Param {
    Scalar(String),
    Vector(Vec<String>),
}