pub mod command_map;
pub mod endpoint;
pub mod http;
pub mod rpc;
pub use command_map::{CommandMapping, map_command};
pub use endpoint::{Endpoint, Scheme};
use crate::error::Result;
use async_trait::async_trait;
use nexus_protocol::rpc::types::NexusValue;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum TransportMode {
NexusRpc,
Resp3,
Http,
Https,
}
impl TransportMode {
pub fn parse(s: &str) -> Option<Self> {
match s.trim().to_ascii_lowercase().as_str() {
"nexus" | "rpc" | "nexusrpc" => Some(Self::NexusRpc),
"resp3" => Some(Self::Resp3),
"http" => Some(Self::Http),
"https" => Some(Self::Https),
"" | "auto" => None,
_ => None,
}
}
pub fn is_rpc(self) -> bool {
matches!(self, Self::NexusRpc)
}
}
impl std::fmt::Display for TransportMode {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str(match self {
Self::NexusRpc => "nexus",
Self::Resp3 => "resp3",
Self::Http => "http",
Self::Https => "https",
})
}
}
#[derive(Debug, Clone)]
pub struct TransportRequest {
pub command: String,
pub args: Vec<NexusValue>,
}
#[derive(Debug, Clone)]
pub struct TransportResponse {
pub value: NexusValue,
}
#[async_trait]
pub trait Transport: Send + Sync {
async fn execute(&self, req: TransportRequest) -> Result<TransportResponse>;
fn describe(&self) -> String;
fn is_rpc(&self) -> bool;
}