use downcast_rs::{impl_downcast, Downcast, DowncastSync};
use futures::future::BoxFuture;
use std::{
fmt::{Debug, Display},
hash::Hash,
};
use crate::common::protocol::tunnel::TunnelName;
pub mod cache;
pub mod mapped;
pub mod memory;
#[cfg(feature = "redis-store")]
pub mod redis;
pub trait TunnelRegistry: Downcast + DowncastSync {
type Identifier: Send + Sync + Debug + Clone + Hash + 'static;
type Record: Send + Debug;
type Error: Send + Debug + Display + 'static;
fn lookup<'a>(
&'a self,
tunnel_name: &'a TunnelName,
) -> BoxFuture<'static, Result<Option<Self::Record>, Self::Error>>;
fn register<'a>(
&'a self,
tunnel_name: TunnelName,
record: &'a Self::Record,
) -> BoxFuture<'static, Result<Self::Identifier, Self::Error>>;
fn deregister<'a>(
&'a self,
tunnel_name: &'a TunnelName,
) -> BoxFuture<'static, Result<Option<Self::Record>, Self::Error>>;
fn deregister_identifier<'a>(
&'a self,
identifier: Self::Identifier,
) -> BoxFuture<'static, Result<Option<Self::Record>, Self::Error>>;
}
impl_downcast!(sync TunnelRegistry assoc Identifier, Record, Error);
pub trait AttributeValue<T> {
type Stored;
fn unpack(stored: &Self::Stored) -> T;
fn pack(input: T) -> Self::Stored;
}
pub trait SharedAttributeRegistry: Downcast + DowncastSync {
type Identifier: Send + Sync + Debug + Clone + Hash;
type Error: Debug + Display;
fn lookup_attr<'a, V>(
&'a self,
key: &'a str,
) -> BoxFuture<'static, Result<Option<V>, Self::Error>>;
fn register_attr<'a, V>(
&'a self,
key: &'a str,
value: &'a V,
) -> BoxFuture<'static, Result<Self::Identifier, Self::Error>>;
fn deregister_attr<'a>(
&'a self,
key: &'a str,
) -> BoxFuture<'static, Result<Option<Self::Identifier>, Self::Error>>;
fn deregister_attr_identifier<'a>(
&'a self,
identifier: Self::Identifier,
) -> BoxFuture<'static, Result<Option<Self::Identifier>, Self::Error>>;
}