Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update: handler: can take any single path param in no tuple & Update docs #89

Merged
merged 11 commits into from
Feb 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 25 additions & 10 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,39 @@ jobs:
steps:
- uses: actions/checkout@v4

- name: Install task command
run: sh -c "$(curl --location https://taskfile.dev/install.sh)" -- -d -b /usr/local/bin
- name: Setup mold
run: |
sudo apt install mold clang
echo '[target.x86_64-unknown-linux-gnu]' >> $HOME/.cargo/config.toml
echo 'linker = "clang"' >> $HOME/.cargo/config.toml
echo 'rustflags = ["-C", "link-arg=-fuse-ld=/usr/bin/mold"]' >> $HOME/.cargo/config.toml
cat $HOME/.cargo/config.toml

- uses: actions-rs/toolchain@v1
with:
toolchain: ${{ matrix.toolchain }}
profile: minimal
override: true

- name: Cache cargo tools
id: cache_cargo_tools
- name: Cache cargo subcommands
id: cache_cargo_subcommands
uses: actions/cache@v3
with:
key: ${{ runner.os }}-cargo-install
key: ${{ runner.os }}-cargo-install--sqlx-sccache
path: ~/.cargo/bin
- name: Install cargo tools
if: ${{ steps.cache_cargo_tools.outputs.cache-hit != 'true' }}
run: cargo install sqlx-cli --no-default-features --features native-tls,postgres

- name: Install cargo subcommands
if: ${{ steps.cache_cargo_subcommands.outputs.cache-hit != 'true' }}
run: |
cargo install sqlx-cli --no-default-features --features native-tls,postgres
cargo install sccache --locked

- name: Setup sccache
run: |
echo '[build]' >> $HOME/.cargo/config.toml
echo "rustc-wrapper = \"$HOME/.cargo/bin/sccache\"" >> $HOME/.cargo/config.toml
cat $HOME/.cargo/config.toml

- name: Run tasks
run: task test check ${{ matrix.toolchain == 'nightly' && 'bench' || '' }}
run: |
sh -c "$(curl --location https://taskfile.dev/install.sh)" -- -d -b /usr/local/bin
task test check ${{ matrix.toolchain == 'nightly' && 'bench' || '' }}
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ tokio = { version = "1", features = ["full"] }

```rust,no_run
use ohkami::prelude::*;
use ohkami::typed::status::{OK, NoContent};
use ohkami::typed::status::{NoContent};

async fn health_check() -> NoContent {
NoContent
}

async fn hello(name: &str) -> OK<String> {
OK(format!("Hello, {name}!"))
async fn hello(name: &str) -> String {
format!("Hello, {name}!")
}

#[tokio::main]
Expand Down Expand Up @@ -233,7 +233,7 @@ async fn test_my_ohkami() {
- [ ] WebSocket

## MSRV (Minimum Supported rustc Version)
Latest stable
Latest stable at the time of publication.

## License
ohkami is licensed under MIT LICENSE ([LICENSE](https://github.com/kana-rus/ohkami/blob/main/LICENSE) or [https://opensource.org/licenses/MIT](https://opensource.org/licenses/MIT)).
6 changes: 3 additions & 3 deletions examples/quick_start/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use ohkami::prelude::*;
use ohkami::typed::status::{OK, NoContent};
use ohkami::typed::status::NoContent;

async fn health_check() -> NoContent {
NoContent
}

async fn hello(name: &str) -> OK<String> {
OK(format!("Hello, {name}!"))
async fn hello(name: &str) -> String {
format!("Hello, {name}!")
}

#[tokio::main]
Expand Down
9 changes: 6 additions & 3 deletions ohkami/src/fang/builtin/jwt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -409,11 +409,14 @@ impl JWT {
first_name: &'s str,
familly_name: &'s str,
} impl<'req> crate::FromRequest<'req> for SigninRequest<'req> {
type Error = crate::FromRequestError;
type Error = Response;
fn from_request(req: &'req Request) -> Result<Self, Self::Error> {
serde_json::from_slice(
req.payload().ok_or_else(|| crate::FromRequestError::Static("No payload found"))?
).map_err(|e| crate::FromRequestError::Owned(e.to_string()))
req.payload().ok_or_else(|| Response::BadRequest().text("No payload found"))?
).map_err(|e| {
eprintln!("Failed to deserialize: {}", e.to_string());
Response::InternalServerError()
})
}
}

Expand Down
4 changes: 2 additions & 2 deletions ohkami/src/fang/fangs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ pub(crate) trait FrontFangCaller: Send + Sync {
where Self: Sync + 'c;
}
impl<FF: FrontFang + Send + Sync> FrontFangCaller for FF {
fn call<'c>(&'c self, req: &'c mut Request) -> Pin<Box<dyn Future<Output = Result<(), Response>> + Send + 'c>>
#[inline(always)] fn call<'c>(&'c self, req: &'c mut Request) -> Pin<Box<dyn Future<Output = Result<(), Response>> + Send + 'c>>
where Self: Sync + 'c
{
Box::pin(self.bite(req))
Expand Down Expand Up @@ -70,7 +70,7 @@ pub(crate) trait BackFangCaller: Send + Sync {
where Self: Sync + 'c;
}
impl<BF: BackFang + Send + Sync> BackFangCaller for BF {
fn call<'c>(&'c self, res: &'c mut Response, _req: &'c Request) -> Pin<Box<dyn Future<Output = Result<(), Response>> + Send + 'c>>
#[inline(always)] fn call<'c>(&'c self, res: &'c mut Response, _req: &'c Request) -> Pin<Box<dyn Future<Output = Result<(), Response>> + Send + 'c>>
where Self: Sync + 'c
{
Box::pin(self.bite(res, _req))
Expand Down
4 changes: 2 additions & 2 deletions ohkami/src/fang/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,15 @@ pub(crate) mod proc {
#[derive(Clone)]
pub struct FrontFang(pub(super) Arc<dyn FrontFangCaller>);
impl FrontFang {
pub fn call<'c>(&'c self, req: &'c mut Request) -> Pin<Box<dyn Future<Output = Result<(), Response>> + Send + 'c>> {
#[inline(always)] pub fn call<'c>(&'c self, req: &'c mut Request) -> Pin<Box<dyn Future<Output = Result<(), Response>> + Send + 'c>> {
self.0.call(req)
}
}

#[derive(Clone)]
pub struct BackFang(pub(super) Arc<dyn BackFangCaller>);
impl BackFang {
pub fn call<'c>(&'c self, res: &'c mut Response, req: &'c Request) -> Pin<Box<dyn Future<Output = Result<(), Response>> + Send + 'c>> {
#[inline(always)] pub fn call<'c>(&'c self, res: &'c mut Response, req: &'c Request) -> Pin<Box<dyn Future<Output = Result<(), Response>> + Send + 'c>> {
self.0.call(res, req)
}
}
Expand Down
6 changes: 3 additions & 3 deletions ohkami/src/handler/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ macro_rules! Handlers {
($( $method:ident ),*) => {
impl Handlers {
$(
pub fn $method<Args>(mut self, handler: impl IntoHandler<Args>) -> Self {
pub fn $method<T>(mut self, handler: impl IntoHandler<T>) -> Self {
self.$method.replace(handler.into_handler());
self
}
Expand Down Expand Up @@ -80,13 +80,13 @@ macro_rules! Route {
/// ```
pub trait Route {
$(
fn $method<Args>(self, handler: impl IntoHandler<Args>) -> Handlers;
fn $method<T>(self, handler: impl IntoHandler<T>) -> Handlers;
)*
fn By(self, another: Ohkami) -> ByAnother;
}
impl Route for &'static str {
$(
fn $method<Args>(self, handler: impl IntoHandler<Args>) -> Handlers {
fn $method<T>(self, handler: impl IntoHandler<T>) -> Handlers {
let mut handlers = Handlers::new(self);
handlers.$method.replace(handler.into_handler());
handlers
Expand Down
Loading
Loading