use std::hash::Hash;
use crate::jmap::{methods::ResultField, objects::Object, protocol::Method};
#[derive(Clone, Debug, Deserialize, Eq, Hash, PartialEq, Serialize)]
#[serde(rename_all = "camelCase", untagged)]
pub enum Argument<T: Clone + PartialEq + Eq + Hash> {
Value(T),
#[serde(rename_all = "camelCase")]
ResultReference {
result_of: String,
name: String,
path: String,
},
}
impl<T: Clone + PartialEq + Eq + Hash> Argument<T> {
pub fn value(v: T) -> Self {
Self::Value(v)
}
pub fn reference<M, OBJ, MethodOBJ>(result_of: usize, path: ResultField<M, MethodOBJ>) -> Self
where
M: Method<MethodOBJ>,
MethodOBJ: Object,
OBJ: Object,
{
Self::ResultReference {
result_of: format!("m{result_of}"),
name: M::NAME.to_string(),
path: path.field.to_string(),
}
}
}
impl<T: Clone + PartialEq + Eq + Hash> From<T> for Argument<T> {
fn from(v: T) -> Self {
Self::Value(v)
}
}