use std::sync::Arc;
#[async_trait::async_trait]
pub trait Direction: Send + Sync + std::fmt::Debug {
async fn parse(&self, rocket: &mut crate::Rocket) -> crate::Result<Destination>;
}
#[derive(Debug, Clone)]
pub enum DirectionKind {
Json,
Response,
NoRequest,
Custom(Arc<dyn Direction>),
}
#[derive(Default)]
pub enum Destination {
Json(serde_json::Value),
Response(reqwest::Response),
#[default]
None,
}
impl std::fmt::Debug for Destination {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Destination::Json(v) => f.debug_tuple("Json").field(v).finish(),
Destination::Response(_) => f
.debug_tuple("Response")
.field(&"<reqwest::Response>")
.finish(),
Destination::None => write!(f, "None"),
}
}
}
impl std::fmt::Display for Destination {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Destination::Json(v) => write!(f, "{v}"),
Destination::Response(_) => write!(f, "<HTTP Response>"),
Destination::None => write!(f, "None"),
}
}
}
impl From<serde_json::Value> for Destination {
fn from(value: serde_json::Value) -> Self {
Destination::Json(value)
}
}