Skip to content

Commit

Permalink
fix: clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
fundon committed Oct 26, 2022
1 parent 35ae9ce commit bbe7172
Show file tree
Hide file tree
Showing 19 changed files with 50 additions and 49 deletions.
4 changes: 2 additions & 2 deletions examples/compression/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ async fn index(_req: Request) -> Result<&'static str> {
#[tokio::main]
async fn main() -> Result<()> {
let addr = SocketAddr::from(([127, 0, 0, 1], 3000));
println!("listening on {}", addr);
println!("listening on {addr}");

let app = Router::new()
.route("/", get(index))
.with(compression::Config::default());

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

Ok(())
Expand Down
4 changes: 2 additions & 2 deletions examples/cors/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ async fn options(_req: Request) -> Result<&'static str> {
#[tokio::main]
async fn main() -> Result<()> {
let addr = SocketAddr::from(([127, 0, 0, 1], 3000));
println!("listening on {}", addr);
println!("listening on {addr}");

let app = Router::new()
.route("/", get(index).options(options))
.with(cors::Config::default());

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

Ok(())
Expand Down
4 changes: 2 additions & 2 deletions examples/csrf/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ async fn create(_req: Request) -> Result<&'static str> {
#[tokio::main]
async fn main() -> Result<()> {
let addr = SocketAddr::from(([127, 0, 0, 1], 3000));
println!("listening on {}", addr);
println!("listening on {addr}");

let app = Router::new()
.get("/", index)
Expand All @@ -38,7 +38,7 @@ async fn main() -> Result<()> {
.with(cookie::Config::new());

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

Ok(())
Expand Down
4 changes: 2 additions & 2 deletions examples/forms/form/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ async fn create(Form(post): Form<Post>) -> Result<Response> {
#[tokio::main]
async fn main() -> Result<()> {
let addr = SocketAddr::from(([127, 0, 0, 1], 3000));
println!("listening on {}", addr);
println!("listening on {addr}");

let app = Router::new()
.route("/", get(new).post(create.into_handler()))
// limit body size
.with(limits::Config::default());

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

Ok(())
Expand Down
4 changes: 2 additions & 2 deletions examples/forms/multipart/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ async fn upload(mut form: Multipart) -> Result<Response> {
#[tokio::main]
async fn main() -> Result<()> {
let addr = SocketAddr::from(([127, 0, 0, 1], 3000));
println!("listening on {}", addr);
println!("listening on {addr}");

let app = Router::new()
.get("/", new)
Expand All @@ -53,7 +53,7 @@ async fn main() -> Result<()> {
.with(limits::Config::default());

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

Ok(())
Expand Down
4 changes: 2 additions & 2 deletions examples/hello-world/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ async fn index(_: Request) -> Result<&'static str> {
#[tokio::main]
async fn main() -> Result<()> {
let addr = SocketAddr::from(([127, 0, 0, 1], 3000));
println!("listening on {}", addr);
println!("listening on {addr}");

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

Expand All @@ -19,7 +19,7 @@ async fn main() -> Result<()> {
.serve(ServiceMaker::from(app))
.await
{
println!("{}", err);
println!("{err}");
}

Ok(())
Expand Down
4 changes: 2 additions & 2 deletions examples/otel/metrics/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ async fn index(_: Request) -> Result<&'static str> {
#[tokio::main]
async fn main() -> Result<()> {
let addr = SocketAddr::from(([127, 0, 0, 1], 3000));
println!("listening on {}", addr);
println!("listening on {addr}");

let exporter = {
let controller = controllers::basic(
Expand All @@ -46,7 +46,7 @@ async fn main() -> Result<()> {
.with(otel::metrics::Config::new(meter));

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

Ok(())
Expand Down
4 changes: 2 additions & 2 deletions examples/otel/tracing/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ async fn index(_: Request) -> Result<&'static str> {
#[tokio::main]
async fn main() -> Result<()> {
let addr = SocketAddr::from(([127, 0, 0, 1], 3000));
println!("listening on {}", addr);
println!("listening on {addr}");

let tracer = init_tracer();

Expand All @@ -33,7 +33,7 @@ async fn main() -> Result<()> {
.with(otel::tracing::Config::new(tracer));

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

Ok(())
Expand Down
4 changes: 2 additions & 2 deletions examples/routing/todos/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ async fn delete(mut req: Request) -> Result<StatusCode> {
#[tokio::main]
async fn main() -> Result<()> {
let addr = SocketAddr::from(([127, 0, 0, 1], 3000));
println!("listening on {}", addr);
println!("listening on {addr}");

let db = DB::default();

Expand All @@ -135,7 +135,7 @@ async fn main() -> Result<()> {
.with(middleware::limits::Config::new());

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

Ok(())
Expand Down
4 changes: 2 additions & 2 deletions examples/rustls/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ async fn index(_: Request) -> Result<&'static str> {
#[tokio::main]
async fn main() -> Result<()> {
let addr = SocketAddr::from(([127, 0, 0, 1], 3000));
println!("listening on {}", addr);
println!("listening on {addr}");

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

Expand All @@ -32,7 +32,7 @@ async fn main() -> Result<()> {
.serve(ServiceMaker::from(app))
.await
{
println!("{}", err);
println!("{err}");
}

Ok(())
Expand Down
4 changes: 2 additions & 2 deletions examples/session/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ async fn index(req: Request) -> Result<&'static str> {
#[tokio::main]
async fn main() -> Result<()> {
let addr = SocketAddr::from(([127, 0, 0, 1], 3000));
println!("listening on {}", addr);
println!("listening on {addr}");

let app = Router::new()
.route("/", get(index))
Expand All @@ -38,7 +38,7 @@ async fn main() -> Result<()> {
.with(cookie::Config::new());

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

Ok(())
Expand Down
6 changes: 3 additions & 3 deletions examples/sse/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ async fn stats(req: Request) -> Result<impl IntoResponse> {
{
Ok(loadavg) => Event::default().data(loadavg),
Err(err) => {
println!("{}", err);
println!("{err}");
Event::default().retry(30)
}
}
Expand All @@ -53,7 +53,7 @@ async fn stats(req: Request) -> Result<impl IntoResponse> {
#[tokio::main]
async fn main() -> Result<()> {
let addr = SocketAddr::from(([127, 0, 0, 1], 3000));
println!("listening on {}", addr);
println!("listening on {addr}");

let sys = Arc::new(System::new());

Expand All @@ -62,7 +62,7 @@ async fn main() -> Result<()> {
.route("/stats", get(stats.with(State::new(sys))));

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

Ok(())
Expand Down
4 changes: 2 additions & 2 deletions examples/static-files/embed/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ struct Asset;
#[tokio::main]
async fn main() -> Result<()> {
let addr = SocketAddr::from(([127, 0, 0, 1], 3000));
println!("listening on {}", addr);
println!("listening on {addr}");

let app = Router::new()
.get("/", embed::File::<Asset>::new("index.html"))
.get("/static/*", embed::Dir::<Asset>::default())
.any("/*", |_| async { Ok(StatusCode::NOT_FOUND) });

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

Ok(())
Expand Down
4 changes: 2 additions & 2 deletions examples/static-files/serve/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ async fn index(_: Request) -> Result<&'static str> {
#[tokio::main]
async fn main() -> Result<()> {
let addr = SocketAddr::from(([127, 0, 0, 1], 3000));
println!("listening on {}", addr);
println!("listening on {addr}");

let dir = env::current_dir().unwrap();

Expand All @@ -22,7 +22,7 @@ async fn main() -> Result<()> {
.any("/*", |_| async { Ok(Response::text("Welcome!")) });

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

Ok(())
Expand Down
4 changes: 2 additions & 2 deletions examples/static-routes/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ async fn me(_: Request) -> Result<&'static str> {
#[tokio::main]
async fn main() -> Result<()> {
let addr = SocketAddr::from(([127, 0, 0, 1], 3000));
println!("listening on {}", addr);
println!("listening on {addr}");

let make_svc =
make_service_fn(|_conn| async { Ok::<_, Infallible>(service_fn(|req| serve(req, None))) });

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

Ok(())
Expand Down
4 changes: 2 additions & 2 deletions examples/unix-socket/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ async fn main() -> viz::Result<()> {
}

let path = "/tmp/viz.sock";
println!("listening on {}", &path);
println!("listening on {path}");

let listener = UnixListener::bind(path).unwrap();
let incoming = UnixListenerStream::new(listener);
Expand All @@ -28,7 +28,7 @@ async fn main() -> viz::Result<()> {
.serve(ServiceMaker::from(app))
.await
{
println!("{}", err);
println!("{err}");
}

Ok(())
Expand Down
6 changes: 3 additions & 3 deletions examples/websocket-chat/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ async fn ws(mut req: Request) -> Result<impl IntoResponse> {
while let Some(Ok(msg)) = ws_rx.next().await {
if let Message::Text(text) = msg {
// Maybe should check user name, dont send to current user.
if tx.send(format!("{}: {}", name, text)).is_err() {
if tx.send(format!("{name}: {text}")).is_err() {
break;
}
}
Expand All @@ -51,7 +51,7 @@ async fn ws(mut req: Request) -> Result<impl IntoResponse> {
#[tokio::main]
async fn main() -> Result<()> {
let addr = SocketAddr::from(([127, 0, 0, 1], 3000));
println!("listening on {}", addr);
println!("listening on {addr}");

let channel = channel::<String>(32);

Expand All @@ -60,7 +60,7 @@ async fn main() -> Result<()> {
.route("/ws/:name", get(ws.with(State::new(channel.0))));

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

Ok(())
Expand Down
23 changes: 12 additions & 11 deletions viz/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@

## Features

* **Safety** `#![forbid(unsafe_code)]`
- **Safety** `#![forbid(unsafe_code)]`

* Lightweight
- Lightweight

* Robust `Routing`
- Robust `Routing`

* Handy `Extractors`
- Handy `Extractors`

* Simple + Flexible `Handler` & `Middleware`
- Simple + Flexible `Handler` & `Middleware`

## Hello Viz

Expand All @@ -58,22 +58,23 @@ async fn index(_: Request) -> Result<&'static str> {
#[tokio::main]
async fn main() -> Result<()> {
let addr = SocketAddr::from(([127, 0, 0, 1], 3000));
println!("listening on {}", addr);
println!("listening on {addr}");

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

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

Ok(())
}
```

More examples can be found [here](https://github.com/viz-rs/viz/tree/main/examples).
More examples can be found
[here](https://github.com/viz-rs/viz/tree/main/examples).

## License

Expand All @@ -82,6 +83,6 @@ Licensed under either of [Apache License, Version 2.0](LICENSE-APACHE) or

### Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted
for inclusion in Viz by you, as defined in the Apache-2.0 license, shall
be dual licensed as above, without any additional terms or conditions.
Unless you explicitly state otherwise, any contribution intentionally submitted
for inclusion in Viz by you, as defined in the Apache-2.0 license, shall be dual
licensed as above, without any additional terms or conditions.
4 changes: 2 additions & 2 deletions viz/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@
//! #[tokio::main]
//! async fn main() -> Result<()> {
//! let addr = SocketAddr::from(([127, 0, 0, 1], 3000));
//! println!("listening on {}", addr);
//! println!("listening on {addr}");
//!
//! let app = Router::new().get("/", index);
//!
//! if let Err(err) = Server::bind(&addr)
//! .serve(ServiceMaker::from(app))
//! .await
//! {
//! println!("{}", err);
//! println!("{err}");
//! }
//!
//! Ok(())
Expand Down

0 comments on commit bbe7172

Please sign in to comment.