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

chore(examples): use std lazy lock instead of once_cell #146

Merged
merged 3 commits into from
Jul 25, 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
2 changes: 1 addition & 1 deletion examples/hello-world/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ async fn main() -> Result<()> {
let mut app = Router::new().get("/", |_| async { Ok("Hello, World!") });

for n in 0..1000 {
app = app.get(&format!("/{}", n), index);
app = app.get(format!("/{}", n), index);
}

if let Err(e) = serve(listener, app).await {
Expand Down
1 change: 0 additions & 1 deletion examples/htmlx/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,3 @@ serde_json.workspace = true
tokio = { workspace = true, features = ["rt-multi-thread", "macros"] }

handlebars = { version = "5", features = ["dir_source"] }
once_cell = "1"
5 changes: 2 additions & 3 deletions examples/htmlx/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
// #![deny(warnings)]

use handlebars::{DirectorySourceOptions, Handlebars};
use once_cell::sync::Lazy;
use serde::{Deserialize, Serialize};
use serde_json::json;
use std::{
env,
net::SocketAddr,
path::PathBuf,
sync::{Arc, Mutex, PoisonError},
sync::{Arc, LazyLock, Mutex, PoisonError},
};
use tokio::net::TcpListener;
use viz::{
Expand All @@ -25,7 +24,7 @@ struct Todo {
pub completed: bool,
}

static TPLS: Lazy<Handlebars> = Lazy::new(|| {
static TPLS: LazyLock<Handlebars> = LazyLock::new(|| {
let dir = env::var("CARGO_MANIFEST_DIR").map(PathBuf::from).unwrap();
let mut h = Handlebars::new();
h.register_templates_directory(dir.join("templates"), DirectorySourceOptions::default())
Expand Down
1 change: 0 additions & 1 deletion examples/static-routes/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,3 @@ viz.workspace = true

hyper.workspace = true
tokio = { workspace = true, features = ["rt-multi-thread", "macros"] }
once_cell = "1"
8 changes: 5 additions & 3 deletions examples/static-routes/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

use hyper::server::conn::http1;
use hyper::service::service_fn;
use once_cell::sync::Lazy;
use std::{net::SocketAddr, sync::Arc};
use std::{
net::SocketAddr,
sync::{Arc, LazyLock},
};
use tokio::net::TcpListener;

use viz::{
Expand All @@ -13,7 +15,7 @@ use viz::{
};

/// Static Lazy Routes
static TREE: Lazy<Tree> = Lazy::new(|| Router::new().get("/", index).get("/me", me).into());
static TREE: LazyLock<Tree> = LazyLock::new(|| Router::new().get("/", index).get("/me", me).into());

async fn index(_: Request) -> Result<&'static str> {
Ok("Hello, World!")
Expand Down
1 change: 0 additions & 1 deletion examples/templates/minijinja/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,3 @@ viz.workspace = true
serde.workspace = true
tokio = { workspace = true, features = ["rt-multi-thread", "macros"] }
minijinja = { version = "2", features = ["loader"] }
once_cell = "1.19"
5 changes: 2 additions & 3 deletions examples/templates/minijinja/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
#![deny(warnings)]
#![allow(clippy::unused_async)]

use std::{env, net::SocketAddr, path::PathBuf};
use std::{env, net::SocketAddr, path::PathBuf, sync::LazyLock};

use minijinja::{context, path_loader, Environment};
use once_cell::sync::Lazy;
use serde::Serialize;
use tokio::net::TcpListener;
use viz::{serve, Error, Request, Response, ResponseExt, Result, Router};

static TPLS: Lazy<Environment> = Lazy::new(|| {
static TPLS: LazyLock<Environment> = LazyLock::new(|| {
let dir = env::var("CARGO_MANIFEST_DIR").map(PathBuf::from).unwrap();
let mut env = Environment::new();
env.set_loader(path_loader(dir.join("templates")));
Expand Down
1 change: 0 additions & 1 deletion examples/templates/tera/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,3 @@ serde.workspace = true
tokio = { workspace = true, features = ["rt-multi-thread", "macros"] }

tera = "1.19"
once_cell = "1"
7 changes: 3 additions & 4 deletions examples/templates/tera/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
#![deny(warnings)]

use std::net::SocketAddr;
use std::{net::SocketAddr, sync::LazyLock};

use once_cell::sync::Lazy;
use serde::Serialize;
use tera::{Context, Tera};
use tokio::net::TcpListener;
use viz::{serve, Error, Request, Response, ResponseExt, Result, Router};

static TPLS: Lazy<Tera> =
Lazy::new(|| Tera::new("examples/templates/tera/templates/**/*").unwrap());
static TPLS: LazyLock<Tera> =
LazyLock::new(|| Tera::new("examples/templates/tera/templates/**/*").unwrap());

#[derive(Serialize)]
struct User<'a> {
Expand Down
5 changes: 0 additions & 5 deletions viz-core/src/types/params/de.rs
Original file line number Diff line number Diff line change
Expand Up @@ -496,11 +496,6 @@ mod tests {
value: String,
}

#[derive(Deserialize)]
struct Id {
_id: String,
}

#[derive(Debug, Deserialize)]
struct Test1(String, u32);

Expand Down
Loading