AscendingCreations / AxumSession

Axum Session Management Libraries that use Sqlx
MIT License
148 stars 33 forks source link

Can I make it compiled with latest axum version on github? #52

Closed WindSoilder closed 10 months ago

WindSoilder commented 1 year ago

I've the following code:

use axum::{routing::get, Router};
use axum_session::{Session, SessionConfig, SessionLayer, SessionNullPool, SessionStore};

#[tokio::main]
async fn main() {
    let session_config = SessionConfig::default().with_table_name("sessions_table");

    let session_store = SessionStore::<SessionNullPool>::new(None, session_config)
        .await
        .unwrap();

    // build our application with some routes
    let app = Router::new()
        .route("/greet", get(greet))
        .layer(SessionLayer::new(session_store));

    // run it
    let listener = tokio::net::TcpListener::bind(format!("0.0.0.0:3000"))
        .await
        .unwrap();
    axum::serve(listener, app.into_make_service())
        .await
        .unwrap()
}

async fn greet(session: Session<SessionNullPool>) -> String {
    let mut count: usize = session.get("count").unwrap_or(0);

    count += 1;
    session.set("count", count);

    count.to_string()
}

And with the following Cargo.toml:

[package]
name = "aaa"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
axum = { git = "https://github.com/tokio-rs/axum.git", features = ["tokio"] }
axum_session = { version = "0.3" }
tokio = { version = "1.28", features = ["macros", "net"]}

But finally it's failed to compile, I get the following error message:

error[E0277]: the trait bound `fn(Session<SessionNullPool>) -> impl Future<Output = String> {greet}: Handler<_, _>` is not satisfied
genusistimelord commented 1 year ago

I would need to update it to support the latest since Axum has a lot of changes. generally though as David's advice would be to not use the master branch of Axum yet as it will still be going through many possible changes till its release. Ill see about pushing a branch later updated to Axum Main branch.

genusistimelord commented 1 year ago

I looked into this and due to the new changes that are coming I will need to wait. Since those new changes need to stabilize a bit before I can make the change over. The issue currently is the current Axum is trying to pull in 2 separate hyper versions which do make it impossible for me to compile anything until its been stabilized.

genusistimelord commented 10 months ago

I have completed this. both axum_session and axum_session_auth are on axum 0.7