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

no serve in the root #98

Closed
Baiyuetribe opened this issue Nov 25, 2023 · 9 comments
Closed

no serve in the root #98

Baiyuetribe opened this issue Nov 25, 2023 · 9 comments

Comments

@Baiyuetribe
Copy link
Contributor

use std::{net::SocketAddr, sync::Arc};
use tokio::net::TcpListener;
use viz::{serve, Request, Result, Router, Tree};

async fn index(_: Request) -> Result<&'static str> {
    Ok("Hello, World!")
}

#[tokio::main]
async fn main() -> Result<()> {
    let addr = SocketAddr::from(([127, 0, 0, 1], 3000));
    let listener = TcpListener::bind(addr).await?;
    println!("listening on http://{addr}");

    let app = Router::new().get("/", index);
    let tree = Arc::new(Tree::from(app));

    loop {
        let (stream, addr) = listener.accept().await?;
        let tree = tree.clone();
        tokio::task::spawn(serve(stream, tree, Some(addr)));
    }
}

The hello-word above won't run. error[E0432]: unresolved import viz::serve

@Baiyuetribe
Copy link
Contributor Author

    if let Err(err) = Server::bind(&addr).serve(ServiceMaker::from(app)).await {
        println!("{err}");
    }

I also found this works, is it equal to the implementation above?

@fundon
Copy link
Member

fundon commented Nov 27, 2023

I also found this works, is it equal to the implementation above?

No, viz::serve is not landed in v0.4.x branch.

v0.5 will be released this week, so we can use that.

@Baiyuetribe
Copy link
Contributor Author

Baiyuetribe commented Nov 30, 2023

is v0.4.x can not use State? i test some state,like
image

missing state type `alloc::sync::Arc<std::sync::mutex::Mutex<alloc::vec::Vec<leaf::router::Todo>>>`

same issue with sea_orm
image

missing state type `sea_orm::database::db_connection::DatabaseConnection`

@fundon
Copy link
Member

fundon commented Dec 1, 2023

The sea_orm example was added into main, and the main branch is v0.5.x.

I checked it. The todos example works ok.

git switch 0.4.x
cd examples
cargo run --bin todos -- --nocapture

BTW, it also works fine in main branch.

@fundon
Copy link
Member

fundon commented Dec 1, 2023

Maybe you need to add those, add an alias.

/// In-memory todo store
type DB = Arc<Mutex<Vec<Todo>>>;

@Baiyuetribe
Copy link
Contributor Author

yes, it only works with the main branch.
but if you use cargo add viz in your own project. it faild. looking forward to v0.5.x release

@Baiyuetribe
Copy link
Contributor Author

@fundon How can I use 0.5.x in my project now without cloning the entire project? I can't wait for the release of .5.x.

@fundon
Copy link
Member

fundon commented Dec 2, 2023

@Baiyuetribe

See specifying-dependencies-from-git-repositories

[dependencies]
viz  = { git = "https://github.com/viz-rs/viz.git", branch = "main" }

or

[dependencies]
viz  = { git = "https://github.com/viz-rs/viz.git", rev = "0a0a7f7" }

@fundon
Copy link
Member

fundon commented Dec 2, 2023

0.5.0 is released.

@fundon fundon closed this as completed Dec 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants