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

Install according to viz.rs document, but it can't run hello world. #139

Open
dafa168 opened this issue May 9, 2024 · 2 comments
Open

Comments

@dafa168
Copy link

dafa168 commented May 9, 2024

rustc -V
rustc 1.78.0 (9b00956e5 2024-04-29)
windows 10
stable-x86_64-pc-windows-gnu

cargo new app
> cd app
> cargo add viz
> cargo add tokio

config.toml :

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

[dependencies]
tokio = "1.37.0"
viz = "0.8.4"

main.rs

use std::net::SocketAddr;
use viz::{Request, Result, Router, Server, ServiceMaker};

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

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

    let app = Router::new().get("/", index);

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

    Ok(())
}

running :
PS D:\rust\vizapi> cargo run -- --nocaputre
Compiling vizapi v0.1.0 (D:\rust\vizapi)
error: The default runtime flavor is multi_thread, but the rt-multi-thread feature is disabled.
--> src\main.rs:8:1
|
8 | #[tokio::main]
| ^^^^^^^^^^^^^^
|
= note: this error originates in the attribute macro tokio::main (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0432]: unresolved import viz::ServiceMaker
--> src\main.rs:2:44
|
2 | use viz::{Request, Result, Router, Server, ServiceMaker};
| ^^^^^^^^^^^^ no ServiceMaker in the root

error[E0599]: no function or associated item named bind found for struct viz::Server in the current scope
--> src\main.rs:15:31
|
15 | if let Err(err) = Server::bind(&addr)
| ^^^^ function or associated item not found in Server<_, _, _, _>
|
note: if you're trying to build a new viz::Server<_, _, _, _>, consider using viz::Server::<L, E, F, S>::new which returns viz::Server<_, _, _, std::future::Pending<()>>
--> C:\Users\xiaoe.cargo\registry\src\rsproxy.cn-8f6827c7555bfaf8\viz-0.8.4\src\server.rs:54:5
|
54 | / pub fn new(executor: E, listener: L, router: Router, build: F) -> Server<L, E, F, Pending<()>>
55 | | where
56 | | F: Fn(E) -> Builder + Send + 'static,
| |________________________________________________^

Some errors have detailed explanations: E0432, E0599.
For more information about an error, try rustc --explain E0432.
error: could not compile vizapi (bin "vizapi") due to 3 previous errors

@fundon
Copy link
Member

fundon commented May 11, 2024

Thanks for the feedback. I'll check on that.

@fundon
Copy link
Member

fundon commented May 12, 2024

viz.rs hasn't been updated yet.
You can check out https://docs.rs/viz/latest/viz/.

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