Skip to content

Commit

Permalink
MSRV Bump to 1.80.0, drop crate lazy_static and use std::sync::LazyLo…
Browse files Browse the repository at this point in the history
  • Loading branch information
martinfrances107 authored Sep 20, 2024
1 parent 23ce022 commit 99403d0
Show file tree
Hide file tree
Showing 10 changed files with 50 additions and 43 deletions.
3 changes: 2 additions & 1 deletion benchmarks/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
name = "benchmarks"
version = "0.1.0"
edition = "2021"
rust-version.workspace = true
# std::sync::LazyLock is stabilized in Rust version 1.80.0
rust-version = "1.80.0"

[dependencies]
l0410 = { package = "leptos", version = "0.4.10", features = [
Expand Down
18 changes: 9 additions & 9 deletions benchmarks/src/ssr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ fn leptos_ssr_bench(b: &mut Bencher) {
}
}

let rendered = view! {
let rendered = view! {
<main>
<h1>"Welcome to our benchmark page."</h1>
<p>"Here's some introductory text."</p>
Expand Down Expand Up @@ -58,7 +58,7 @@ fn tachys_ssr_bench(b: &mut Bencher) {
}
}

let rendered = view! {
let rendered = view! {
<main>
<h1>"Welcome to our benchmark page."</h1>
<p>"Here's some introductory text."</p>
Expand Down Expand Up @@ -92,13 +92,13 @@ fn tera_ssr_bench(b: &mut Bencher) {
{% endfor %}
</main>"#;

lazy_static::lazy_static! {
static ref TERA: Tera = {
let mut tera = Tera::default();
tera.add_raw_templates(vec![("template.html", TEMPLATE)]).unwrap();
tera
};
}

static LazyCell<TERA>: Tera = LazyLock::new(|| {
let mut tera = Tera::default();
tera.add_raw_templates(vec![("template.html", TEMPLATE)]).unwrap();
tera
});


#[derive(Serialize, Deserialize)]
struct Counter {
Expand Down
24 changes: 12 additions & 12 deletions benchmarks/src/todomvc/tera.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ static TEMPLATE: &str = r#"<main>
{% else %}
<li><a href="/">All</a></li>
{% endif %}
{% if mode_active %}
<li><a href="/active" class="selected">Active</a></li>
{% else %}
Expand Down Expand Up @@ -91,13 +91,13 @@ fn tera_todomvc_ssr(b: &mut Bencher) {
use serde::{Deserialize, Serialize};
use tera::*;

lazy_static::lazy_static! {
static ref TERA: Tera = {

static LazyLock<TERA>: Tera = LazyLock( || {
let mut tera = Tera::default();
tera.add_raw_templates(vec![("template.html", TEMPLATE)]).unwrap();
tera
};
}
});


#[derive(Serialize, Deserialize)]
struct Todo {
Expand Down Expand Up @@ -131,13 +131,13 @@ fn tera_todomvc_ssr_1000(b: &mut Bencher) {
use serde::{Deserialize, Serialize};
use tera::*;

lazy_static::lazy_static! {
static ref TERA: Tera = {
let mut tera = Tera::default();
tera.add_raw_templates(vec![("template.html", TEMPLATE)]).unwrap();
tera
};
}

static TERA: LazyLock<Tera> = LazyLock::new(|| {
let mut tera = Tera::default();
tera.add_raw_templates(vec![("template.html", TEMPLATE)]).unwrap();
tera
});


#[derive(Serialize, Deserialize)]
struct Todo {
Expand Down
7 changes: 4 additions & 3 deletions examples/counter_isomorphic/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
name = "counter_isomorphic"
version = "0.1.0"
edition = "2021"
# std::sync::LazyLock is stabilized in Rust version 1.80.0
rust-version = "1.80.0"

[lib]
crate-type = ["cdylib", "rlib"]
Expand All @@ -17,7 +19,6 @@ broadcaster = "1.0"
console_log = "1.0"
console_error_panic_hook = "0.1.7"
futures = "0.3.30"
lazy_static = "1.5"
leptos = { path = "../../leptos" }
leptos_actix = { path = "../../integrations/actix", optional = true }
leptos_router = { path = "../../router" }
Expand Down Expand Up @@ -46,13 +47,13 @@ denylist = ["actix-files", "actix-web", "leptos_actix"]
skip_feature_sets = [["ssr", "hydrate"]]

[package.metadata.leptos]
# The name used by wasm-bindgen/cargo-leptos for the JS/WASM bundle. Defaults to the crate name
# The name used by wasm-bindgen/cargo-leptos for the JS/WASM bundle. Defaults to the crate name
output-name = "counter_isomorphic"
# The site root folder is where cargo-leptos generate all output. WARNING: all content of this folder will be erased on a rebuild. Use it in your server setup.
# When NOT using cargo-leptos this must be updated to "." or the counters will not work. The above warning still applies if you do switch to cargo-leptos later.
site-root = "target/site"
# The site-root relative folder where all compiled output (JS, WASM and CSS) is written
# Defaults to pkg
# Defaults to pkg
site-pkg-dir = "pkg"
# [Optional] The source CSS file. If it ends with .sass or .scss then it will be compiled by dart-sass into CSS. The CSS is optimized by Lightning CSS before being written to <site-root>/<site-pkg>/app.css
# style-file = "src/styles/tailwind.css"
Expand Down
6 changes: 3 additions & 3 deletions examples/counter_isomorphic/src/counters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ use tracing::instrument;
pub mod ssr_imports {
pub use broadcaster::BroadcastChannel;
pub use std::sync::atomic::{AtomicI32, Ordering};
use std::sync::LazyLock;

pub static COUNT: AtomicI32 = AtomicI32::new(0);

lazy_static::lazy_static! {
pub static ref COUNT_CHANNEL: BroadcastChannel<i32> = BroadcastChannel::new();
}
pub static COUNT_CHANNEL: LazyLock<BroadcastChannel<i32>> =
LazyLock::new(BroadcastChannel::<i32>::new);
}

#[server]
Expand Down
1 change: 0 additions & 1 deletion examples/hackernews_islands_axum/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ tokio = { version = "1.39", features = ["full"], optional = true }
http = { version = "1.1", optional = true }
web-sys = { version = "0.3.70", features = ["AbortController", "AbortSignal"] }
wasm-bindgen = "0.2.93"
lazy_static = "1.5"
rust-embed = { version = "8.5", features = [
"axum",
"mime_guess",
Expand Down
7 changes: 4 additions & 3 deletions examples/ssr_modes/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
name = "ssr_modes"
version = "0.1.0"
edition = "2021"
# std::sync::LazyLock is stabilized in Rust version 1.80.0
rust-version = "1.80.0"

[lib]
crate-type = ["cdylib", "rlib"]
Expand All @@ -11,7 +13,6 @@ actix-files = { version = "0.6.6", optional = true }
actix-web = { version = "4.8", optional = true, features = ["macros"] }
console_error_panic_hook = "0.1.7"
console_log = "1.0"
lazy_static = "1.5"
leptos = { path = "../../leptos" }
leptos_meta = { path = "../../meta" }
leptos_actix = { path = "../../integrations/actix", optional = true }
Expand All @@ -38,12 +39,12 @@ denylist = ["actix-files", "actix-web", "leptos_actix"]
skip_feature_sets = [["ssr", "hydrate"]]

[package.metadata.leptos]
# The name used by wasm-bindgen/cargo-leptos for the JS/WASM bundle. Defaults to the crate name
# The name used by wasm-bindgen/cargo-leptos for the JS/WASM bundle. Defaults to the crate name
output-name = "ssr_modes"
# The site root folder is where cargo-leptos generate all output. WARNING: all content of this folder will be erased on a rebuild. Use it in your server setup.
site-root = "target/site"
# The site-root relative folder where all compiled output (JS, WASM and CSS) is written
# Defaults to pkg
# Defaults to pkg
site-pkg-dir = "pkg"
# [Optional] The source CSS file. If it ends with .sass or .scss then it will be compiled by dart-sass into CSS. The CSS is optimized by Lightning CSS before being written to <site-root>/<site-pkg>/app.css
style-file = "style/main.scss"
Expand Down
12 changes: 7 additions & 5 deletions examples/ssr_modes/src/app.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use lazy_static::lazy_static;
use std::sync::LazyLock;

use leptos::prelude::*;
use leptos_meta::*;
use leptos_router::{
Expand Down Expand Up @@ -146,8 +147,9 @@ fn Post() -> impl IntoView {
}

// Dummy API
lazy_static! {
static ref POSTS: Vec<Post> = vec![

static POSTS: LazyLock<[Post; 3]> = LazyLock::new(|| {
[
Post {
id: 0,
title: "My first post".to_string(),
Expand All @@ -163,8 +165,8 @@ lazy_static! {
title: "My third post".to_string(),
content: "This is my third post".to_string(),
},
];
}
]
});

#[derive(Error, Debug, Copy, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub enum PostError {
Expand Down
3 changes: 2 additions & 1 deletion examples/ssr_modes_axum/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@
name = "ssr_modes_axum"
version = "0.1.0"
edition = "2021"
# std::sync::LazyLock is stabilized in Rust version 1.80.0
rust-version = "1.80.0"

[lib]
crate-type = ["cdylib", "rlib"]

[dependencies]
console_error_panic_hook = "0.1.7"
console_log = "1.0"
lazy_static = "1.5"
leptos = { path = "../../leptos", features = [
"hydration",
] } #"nightly", "hydration"] }
Expand Down
12 changes: 7 additions & 5 deletions examples/ssr_modes_axum/src/app.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use lazy_static::lazy_static;
use std::sync::LazyLock;

use leptos::prelude::*;
use leptos_meta::MetaTags;
use leptos_meta::*;
Expand Down Expand Up @@ -261,8 +262,9 @@ pub fn Admin() -> impl IntoView {
}

// Dummy API
lazy_static! {
static ref POSTS: Vec<Post> = vec![

static POSTS: LazyLock<[Post; 3]> = LazyLock::new(|| {
[
Post {
id: 0,
title: "My first post".to_string(),
Expand All @@ -278,8 +280,8 @@ lazy_static! {
title: "My third post".to_string(),
content: "This is my third post".to_string(),
},
];
}
]
});

#[derive(Error, Debug, Copy, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub enum PostError {
Expand Down

0 comments on commit 99403d0

Please sign in to comment.