-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
50ba4c3
commit e1cde93
Showing
13 changed files
with
202 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
[package] | ||
name = "rspc-core2" | ||
version = "0.0.0" | ||
edition = "2021" | ||
publish = false | ||
|
||
[dependencies] | ||
futures-core = "0.3" | ||
erased-serde = "0.4.1" | ||
|
||
[dev-dependencies] | ||
tokio = { version = "1", features = ["full"] } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
FORMAT AGNOSTIC | ||
|
||
Async context functions | ||
|
||
Allow streaming large files to the `result` | ||
|
||
Tracing integration | ||
Benchmark proper trie router | ||
|
||
Remove `erased-serde` from the public API | ||
|
||
|
||
What if forget to call `ctx.result.serialize_*`??? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
use std::{borrow::Cow, collections::HashMap, future::Future, pin::Pin}; | ||
|
||
use erased_serde::Deserializer; | ||
|
||
use crate::serializer::Serializer; | ||
|
||
pub struct RequestContext<'a> { | ||
// pub id: u32, | ||
pub arg: Option<&'a mut (dyn Deserializer<'a> + Send)>, // TODO: Remove `erased-serde` from public API | ||
pub result: Serializer<'a>, | ||
} | ||
|
||
#[derive(Default)] | ||
pub struct Executor { | ||
procedures: HashMap<Cow<'static, str>, Procedure>, | ||
} | ||
|
||
impl Executor { | ||
// pub async fn execute() -> () {} | ||
|
||
// pub async fn execute_blocking() -> () {} | ||
|
||
// pub async fn execute_streaming() -> () {} | ||
|
||
// TODO: How can the user get a `Value` without major overhead | ||
} | ||
|
||
pub struct Procedure { | ||
// TODO: Make this private | ||
pub handler: Box<dyn Fn(RequestContext) -> Pin<Box<dyn Future<Output = ()> + Send + '_>>>, | ||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
//! rspc core | ||
|
||
// TODO: Clippy lints | ||
|
||
mod executor; | ||
#[doc(hidden)] | ||
pub mod internal; | ||
mod router; | ||
mod serializer; | ||
mod task; | ||
|
||
// pub trait Body = Stream<Item = Vec<u8>>; // TODO: Should this allow returning `Value` | ||
|
||
pub use executor::{Executor, Procedure}; | ||
pub use router::Router; | ||
pub use task::Task; | ||
|
||
// // TODO: How can `ctx_fn` get stuff from request context or Tauri handle??? | ||
// pub fn todo_router<R: Router>(router: R, ctx_fn: impl Fn() -> R::Ctx) { | ||
// let executor = router.build(); | ||
|
||
// // executor.execute(); | ||
// } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
use crate::Executor; | ||
|
||
// TODO: Seal this | ||
pub trait Router { | ||
type Ctx; | ||
|
||
fn build(self) -> Executor; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
pub struct Serializer<'a> { | ||
serializer: &'a mut (dyn erased_serde::Serializer + Send), | ||
} | ||
|
||
impl<'a> Serializer<'a> {} | ||
|
||
// TODO: How could this serialize bytes/files | ||
|
||
// pub struct BytesSerializer {} | ||
|
||
// pub struct ValueSerializer {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
use std::{ | ||
fmt, | ||
future::Future, | ||
pin::Pin, | ||
task::{Context, Poll}, | ||
}; | ||
|
||
use futures_core::{FusedStream, Stream}; | ||
|
||
pub struct Task { | ||
pub id: u32, | ||
// pub should_be_queued: bool, | ||
// done: bool, | ||
stream: Pin<Box<dyn Future<Output = ()> + Send>>, | ||
} | ||
|
||
impl fmt::Debug for Task { | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
f.debug_struct("Task").field("id", &self.id).finish() | ||
} | ||
} | ||
|
||
impl Stream for Task { | ||
type Item = Vec<u8>; // TODO: What if the user wants `serde_json::Value` | ||
|
||
fn poll_next(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> { | ||
todo!() | ||
} | ||
} | ||
|
||
impl FusedStream for Task { | ||
fn is_terminated(&self) -> bool { | ||
todo!() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
use rspc_core2::Procedure; | ||
|
||
#[tokio::test] | ||
async fn test_procedure() { | ||
let _p = Procedure { | ||
handler: Box::new(|ctx| { | ||
Box::pin(async move { | ||
let _input: String = erased_serde::deserialize(ctx.arg.unwrap()).unwrap(); | ||
// ctx.result.erased_serialize_str("todo"); | ||
// TODO | ||
}) | ||
}), | ||
}; | ||
|
||
let _p = Procedure { | ||
handler: Box::new(|ctx| { | ||
Box::pin(async move { | ||
let _input: String = erased_serde::deserialize(ctx.arg.unwrap()).unwrap(); | ||
// ctx.result.erased_serialize_str("todo"); | ||
// TODO: Stream multiple JSON results | ||
}) | ||
}), | ||
}; | ||
|
||
let _p = Procedure { | ||
handler: Box::new(|ctx| { | ||
Box::pin(async move { | ||
let _input: String = erased_serde::deserialize(ctx.arg.unwrap()).unwrap(); | ||
// ctx.result.erased_serialize_str("todo"); | ||
// TODO: Stream entire file worth of bytes | ||
}) | ||
}), | ||
}; | ||
} | ||
|
||
#[tokio::test] | ||
async fn test_executor() { | ||
// TODO: | ||
// let executor = Executor::default(); | ||
// executor. | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters