diff --git a/crates/rpc/src/j2.rs b/crates/rpc/src/j2.rs deleted file mode 100644 index 93ecd6982d..0000000000 --- a/crates/rpc/src/j2.rs +++ /dev/null @@ -1,188 +0,0 @@ -// #![allow(dead_code)] - -// use std::collections::HashMap; -// use std::marker::PhantomData; - -// use futures::Future; -// use serde::de::DeserializeOwned; -// use serde_json::Value; - -// use crate::context::RpcContext; - -// #[derive(Default)] -// struct MethodRouter { -// methods: HashMap<&'static str, Box>, -// } - -// impl MethodRouter { -// fn register( -// mut self, -// method_name: &'static str, -// method: impl IntoMethod + 'static, -// ) -> Self { -// self.methods.insert(method_name, method.into_method()); -// self -// } - -// async fn invoke( -// &self, -// method: &str, -// input: Value, -// state: RpcContext, -// ) -> Result { -// match self.methods.get(method) { -// Some(method) => method.invoke(input, state).await.map_err(Into::into), -// None => Err(crate::jsonrpc::RpcError::MethodNotFound { -// method: method.to_owned(), -// }), -// } -// } -// } - -// #[axum::async_trait] -// trait Method { -// async fn invoke( -// &self, -// input: Value, -// state: RpcContext, -// ) -> Result; -// } - -// trait IntoMethod { -// fn into_method(self) -> Box; -// } - -// /// impl for -// /// () -> T -// /// input only -// /// state only -// /// input and state - - - -// impl<'de, Func, Fut, Input> IntoMethod<((), Input)> for Func -// where -// Func: Fn(Input) -> Fut + Clone + 'static + std::marker::Sync + std::marker::Send, -// Fut: Future + std::marker::Send + 'static, -// Input: DeserializeOwned + std::marker::Sync + std::marker::Send + 'static, -// { -// fn into_method(self) -> Box { -// struct HandlerImpl -// where -// Func: Fn(Input) -> Fut + Clone, -// Fut: Future, -// { -// f: Func, -// _marker: PhantomData, -// } - -// #[axum::async_trait] -// impl<'de, Func, Fut, Input> Method for HandlerImpl -// where -// Func: Fn(Input) -> Fut + Clone + 'static + std::marker::Sync + std::marker::Send, -// Fut: Future + std::marker::Send, -// Input: DeserializeOwned + std::marker::Sync + std::marker::Send + 'static, -// { -// async fn invoke(&self, input: Value) -> u32 { -// let input: Input = serde_json::from_value(input).unwrap(); -// let f = self.f.clone(); -// async move { f(input).await }.await -// } -// } - -// Box::new(HandlerImpl { -// f: self, -// _marker: Default::default(), -// }) as Box -// } -// } - -// impl IntoMethod for Func -// where -// Func: Fn(u32) -> Fut + Clone + 'static + std::marker::Sync + std::marker::Send, -// Fut: Future + std::marker::Send + 'static, -// { -// fn into_method(self) -> Box { -// struct HandlerImpl -// where -// Func: Fn(u32) -> Fut + Clone, -// Fut: Future, -// { -// f: Func, -// } - -// #[derive(serde::Deserialize)] -// struct Input(u32); - -// #[axum::async_trait] -// impl Method for HandlerImpl -// where -// Func: Fn(u32) -> Fut + Clone + std::marker::Sync + std::marker::Send, -// Fut: Future + std::marker::Send, -// { -// async fn invoke(&self, input: Value) -> u32 { -// let input: Input = serde_json::from_value(input).unwrap(); -// let f = self.f.clone(); -// f(input.0).await -// } -// } - -// Box::new(HandlerImpl { f: self }) as Box -// } -// } - -// impl IntoMethod<()> for Func -// where -// Func: Fn() -> Value + Clone + 'static + std::marker::Sync, -// { -// fn into_method(self) -> Box { -// struct HandlerImpl u32 + Clone> { -// f: Func, -// } - -// #[axum::async_trait] -// impl u32 + Clone + std::marker::Sync> Method for HandlerImpl { -// async fn invoke(&self, _input: Value) -> u32 { -// let f = self.f.clone(); -// f() -// } -// } - -// Box::new(HandlerImpl { f: self }) as Box -// } -// } - -// #[tokio::test] -// async fn feature() { -// async fn echo(x: u32) -> u32 { -// x -// } - -// fn always_10() -> u32 { -// 10 -// } - -// async fn double(x: u32) -> u32 { -// x * 2 -// } - -// #[derive(serde::Deserialize)] -// struct In(u32); - -// async fn echo_serde(input: In) -> u32 { -// input.0 -// } - -// let router = MethodRouter::default() -// .register::("echo", echo) -// .register("always_10", always_10) -// .register::("double", double) -// .register("echo_serde", echo_serde); - -// let input = Value::Number(20.into()); - -// assert_eq!(router.invoke("echo_serde", input.clone()).await, 20); -// assert_eq!(router.invoke("echo", input.clone()).await, 20); -// assert_eq!(router.invoke("always_10", input.clone()).await, 10); -// assert_eq!(router.invoke("double", input).await, 20 * 2); -// }