Skip to content

Commit

Permalink
Remove once_cell and use standard library (#826)
Browse files Browse the repository at this point in the history
* Remove once_cell and use standard library

* Format Rust code using rustfmt

* wip

* fix: Compression middleware does not set body back if body can not compress (#827)

* use Into<ResBody> to set response body (#828)

* fix-ci

* chore(deps): update salvo-http3 requirement from 0.2.0 to 0.3.0 (#829)

---
updated-dependencies:
- dependency-name: salvo-http3
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* fix: Request local_addr doc (#831)

* Version 0.68.5

* chore: Update opentelemetry dependencies (#837)

* chore: Update opentelemetry dependencies

* Format Rust code using rustfmt

* update examples

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* Update readme

* wip

* wip

---------

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Aston Turing <[email protected]>
  • Loading branch information
4 people authored Jul 25, 2024
1 parent f757a7c commit 6d4dca5
Show file tree
Hide file tree
Showing 49 changed files with 123 additions and 509 deletions.
3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ resolver = "2"
version = "0.68.5"
authors = ["Chrislearn Young <[email protected]>"]
edition = "2021"
rust-version = "1.76"
rust-version = "1.80"
description = """
Salvo is a powerful web framework that can make your work easier.
"""
Expand Down Expand Up @@ -79,7 +79,6 @@ multer = "3"
multimap = "0.10"
native-tls = "0.2"
nix = { version = "0.29", default-features = false }
once_cell = "1"
openssl = "0.10"
opentelemetry = { version = "0.24", default-features = false }
opentelemetry-http = { version = "0.13", default-features = false }
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<a href="https://crates.io/crates/salvo"><img alt="crates.io" src="https://img.shields.io/crates/v/salvo" /></a>
<a href="https://docs.rs/salvo"><img alt="Documentation" src="https://docs.rs/salvo/badge.svg" /></a>
<a href="https://github.com/rust-secure-code/safety-dance/"><img alt="unsafe forbidden" src="https://img.shields.io/badge/unsafe-forbidden-success.svg" /></a>
<a href="https://blog.rust-lang.org/2024/02/08/Rust-1.76.0.html"><img alt="Rust Version" src="https://img.shields.io/badge/rust-1.76%2B-blue" /></a>
<a href="https://blog.rust-lang.org/2024/07/25/Rust-1.80.0.html"><img alt="Rust Version" src="https://img.shields.io/badge/rust-1.80%2B-blue" /></a>
<br>
<a href="https://salvo.rs">
<img alt="Website" src="https://img.shields.io/badge/https-salvo.rs-%23f00" />
Expand Down
2 changes: 1 addition & 1 deletion README.osc.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<a href="https://crates.io/crates/salvo"><img alt="crates.io" src="https://img.shields.io/crates/v/salvo" /></a>
<a href="https://docs.rs/salvo"><img alt="Documentation" src="https://docs.rs/salvo/badge.svg" /></a>
<a href="https://github.com/rust-secure-code/safety-dance/"><img alt="unsafe forbidden" src="https://img.shields.io/badge/unsafe-forbidden-success.svg" /></a>
<a href="https://blog.rust-lang.org/2024/02/08/Rust-1.76.0.html"><img alt="Rust Version" src="https://img.shields.io/badge/rust-1.76%2B-blue" /></a>
<a href="https://blog.rust-lang.org/2024/07/25/Rust-1.80.0.html"><img alt="Rust Version" src="https://img.shields.io/badge/rust-1.80%2B-blue" /></a>
<br>
<a href="https://salvo.rs">
<img alt="Website" src="https://img.shields.io/badge/https-salvo.rs-%23f00" />
Expand Down
2 changes: 1 addition & 1 deletion README.zh-hans.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<a href="https://crates.io/crates/salvo"><img alt="crates.io" src="https://img.shields.io/crates/v/salvo" /></a>
<a href="https://docs.rs/salvo"><img alt="Documentation" src="https://docs.rs/salvo/badge.svg" /></a>
<a href="https://github.com/rust-secure-code/safety-dance/"><img alt="unsafe forbidden" src="https://img.shields.io/badge/unsafe-forbidden-success.svg" /></a>
<a href="https://blog.rust-lang.org/2024/02/08/Rust-1.76.0.html"><img alt="Rust Version" src="https://img.shields.io/badge/rust-1.76%2B-blue" /></a>
<a href="https://blog.rust-lang.org/2024/07/25/Rust-1.80.0.html"><img alt="Rust Version" src="https://img.shields.io/badge/rust-1.80%2B-blue" /></a>
<br>
<a href="https://salvo.rs">
<img alt="Website" src="https://img.shields.io/badge/https-salvo.rs-%23f00" />
Expand Down
2 changes: 1 addition & 1 deletion README.zh-hant.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<a href="https://crates.io/crates/salvo"><img alt="crates.io" src="https://img.shields.io/crates/v/salvo" /></a>
<a href="https://docs.rs/salvo"><img alt="Documentation" src="https://docs.rs/salvo/badge.svg" /></a>
<a href="https://github.com/rust-secure-code/safety-dance/"><img alt="unsafe forbidden" src="https://img.shields.io/badge/unsafe-forbidden-success.svg" /></a>
<a href="https://blog.rust-lang.org/2024/02/08/Rust-1.76.0.html"><img alt="Rust Version" src="https://img.shields.io/badge/rust-1.76%2B-blue" /></a>
<a href="https://blog.rust-lang.org/2024/07/25/Rust-1.80.0.html"><img alt="Rust Version" src="https://img.shields.io/badge/rust-1.80%2B-blue" /></a>
<br>
<a href="https://salvo.rs">
<img alt="Website" src="https://img.shields.io/badge/https-salvo.rs-%23f00" />
Expand Down
1 change: 0 additions & 1 deletion crates/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ mime-infer = { workspace = true }
multer = { workspace = true }
multimap = { workspace = true, features = ["serde"] }
native-tls = { workspace = true, optional = true, features = ["alpn"] }
once_cell = { workspace = true }
openssl = { workspace = true, optional = true }
percent-encoding = { workspace = true }
pin-project = { workspace = true }
Expand Down
6 changes: 3 additions & 3 deletions crates/core/src/catcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,19 @@
//! handler can call [`FlowCtrl::skip_rest()`] method to skip next error handlers and return early.

use std::borrow::Cow;
use std::sync::Arc;
use std::sync::{Arc, LazyLock};

use async_trait::async_trait;
use bytes::Bytes;
use mime::Mime;
use once_cell::sync::Lazy;
use serde::Serialize;

use crate::handler::{Handler, WhenHoop};
use crate::http::{guess_accept_mime, header, Request, ResBody, Response, StatusCode, StatusError};
use crate::{Depot, FlowCtrl};

static SUPPORTED_FORMATS: Lazy<Vec<mime::Name>> = Lazy::new(|| vec![mime::JSON, mime::HTML, mime::XML, mime::PLAIN]);
static SUPPORTED_FORMATS: LazyLock<Vec<mime::Name>> =
LazyLock::new(|| vec![mime::JSON, mime::HTML, mime::XML, mime::PLAIN]);
const EMPTY_CAUSE_MSG: &str = "There is no more detailed explanation.";
const SALVO_LINK: &str = r#"<a href="https://salvo.rs" target="_blank">salvo</a>"#;

Expand Down
12 changes: 6 additions & 6 deletions crates/core/src/http/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::error::Error as StdError;
use std::fmt::{self, Formatter};
#[cfg(feature = "quinn")]
use std::sync::Arc;
use std::sync::OnceLock;

use bytes::Bytes;
#[cfg(feature = "cookie")]
Expand All @@ -15,7 +16,6 @@ use http::Extensions;
use http_body_util::{BodyExt, Limited};
use indexmap::IndexMap;
use multimap::MultiMap;
use once_cell::sync::OnceCell;
use parking_lot::RwLock;
use serde::de::Deserialize;

Expand Down Expand Up @@ -64,7 +64,7 @@ pub struct Request {
pub(crate) params: IndexMap<String, String>,

// accept: Option<Vec<Mime>>,
pub(crate) queries: OnceCell<MultiMap<String, String>>,
pub(crate) queries: OnceLock<MultiMap<String, String>>,
pub(crate) form_data: tokio::sync::OnceCell<FormData>,
pub(crate) payload: tokio::sync::OnceCell<Bytes>,

Expand Down Expand Up @@ -111,7 +111,7 @@ impl Request {
#[cfg(feature = "cookie")]
cookies: CookieJar::default(),
params: IndexMap::new(),
queries: OnceCell::new(),
queries: OnceLock::new(),
form_data: tokio::sync::OnceCell::new(),
payload: tokio::sync::OnceCell::new(),
version: Version::default(),
Expand Down Expand Up @@ -162,7 +162,7 @@ impl Request {
};

Request {
queries: OnceCell::new(),
queries: OnceLock::new(),
uri,
headers,
body: body.into(),
Expand All @@ -174,7 +174,7 @@ impl Request {
params: IndexMap::new(),
form_data: tokio::sync::OnceCell::new(),
payload: tokio::sync::OnceCell::new(),
// multipart: OnceCell::new(),
// multipart: OnceLock::new(),
local_addr: SocketAddr::Unknown,
remote_addr: SocketAddr::Unknown,
version,
Expand Down Expand Up @@ -266,7 +266,7 @@ impl Request {
#[inline]
pub fn set_uri(&mut self, uri: Uri) {
self.uri = uri;
self.queries = OnceCell::new();
self.queries = OnceLock::new();
}

/// Returns a reference to the associated HTTP method.
Expand Down
1 change: 0 additions & 1 deletion crates/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,6 @@ pub mod prelude {

#[doc(hidden)]
pub mod __private {
pub use once_cell;
pub use tracing;
}

Expand Down
5 changes: 2 additions & 3 deletions crates/core/src/routing/filters/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@

use std::collections::HashMap;
use std::fmt::{self, Formatter};
use std::sync::Arc;
use std::sync::{Arc, LazyLock};

use indexmap::IndexSet;
use once_cell::sync::Lazy;
use parking_lot::RwLock;
use regex::Regex;

Expand Down Expand Up @@ -36,7 +35,7 @@ pub trait WispBuilder: Send + Sync {
}

type WispBuilderMap = RwLock<HashMap<String, Arc<Box<dyn WispBuilder>>>>;
static WISP_BUILDERS: Lazy<WispBuilderMap> = Lazy::new(|| {
static WISP_BUILDERS: LazyLock<WispBuilderMap> = LazyLock::new(|| {
let mut map: HashMap<String, Arc<Box<dyn WispBuilder>>> = HashMap::with_capacity(8);
map.insert("num".into(), Arc::new(Box::new(CharsWispBuilder::new(is_num))));
map.insert("hex".into(), Arc::new(Box::new(CharsWispBuilder::new(is_hex))));
Expand Down
2 changes: 1 addition & 1 deletion crates/core/src/routing/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@
//!
//! - `<id:num>`, matches any number of numeric characters;
//! - `<id:num[10]>`, only matches a certain number of numeric characters, where 10 means that the match only matches
//! 10 numeric characters;
//! 10 numeric characters;
//! - `<id:num(..10)>` means matching 1 to 9 numeric characters;
//! - `<id:num(3..10)>` means matching 3 to 9 numeric characters;
//! - `<id:num(..=10)>` means matching 1 to 10 numeric characters;
Expand Down
2 changes: 1 addition & 1 deletion crates/csrf/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ mod tests {
assert_eq!(res.status_code.unwrap(), StatusCode::OK);
assert_eq!(res.take_string().await.unwrap(), "POST");
}
#[cfg(feadture = "hmac-cipher")]
#[cfg(feature = "hmac-cipher")]
#[tokio::test]
async fn test_validates_token_in_alternate_query() {
let csrf = Csrf::new(
Expand Down
2 changes: 1 addition & 1 deletion crates/macros/src/extract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ pub(crate) fn generate(args: DeriveInput) -> Result<TokenStream, Error> {
let mt = name.to_string();
let metadata = quote! {
fn metadata() -> &'static #salvo::extract::Metadata {
static METADATA: #salvo::__private::once_cell::sync::OnceCell<#salvo::extract::Metadata> = #salvo::__private::once_cell::sync::OnceCell::new();
static METADATA: ::std::sync::OnceLock<#salvo::extract::Metadata> = ::std::sync::OnceLock::new();
METADATA.get_or_init(|| {
let mut metadata = #salvo::extract::Metadata::new(#mt);
#(
Expand Down
6 changes: 2 additions & 4 deletions crates/macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,7 @@ mod tests {
quote!{
impl<'__macro_gen_ex: 'a, 'a> salvo::extract::Extractible<'__macro_gen_ex> for BadMan<'a> {
fn metadata() -> &'static salvo::extract::Metadata {
static METADATA: salvo::__private::once_cell::sync::OnceCell<salvo::extract::Metadata> =
salvo::__private::once_cell::sync::OnceCell::new();
static METADATA: ::std::sync::OnceLock<salvo::extract::Metadata> = ::std::sync::OnceLock::new();
METADATA.get_or_init(|| {
let mut metadata = salvo::extract::Metadata::new("BadMan");
metadata = metadata.add_default_source(salvo::extract::metadata::Source::new(
Expand Down Expand Up @@ -233,8 +232,7 @@ mod tests {
quote!{
impl<'__macro_gen_ex: 'a, 'a> salvo::extract::Extractible<'__macro_gen_ex> for BadMan<'a> {
fn metadata() -> &'static salvo::extract::Metadata {
static METADATA: salvo::__private::once_cell::sync::OnceCell<salvo::extract::Metadata> =
salvo::__private::once_cell::sync::OnceCell::new();
static METADATA: ::std::sync::OnceLock<salvo::extract::Metadata> = ::std::sync::OnceLock::new();
METADATA.get_or_init(|| {
let mut metadata = salvo::extract::Metadata::new("BadMan");
metadata = metadata.add_default_source(salvo::extract::metadata::Source::new(
Expand Down
3 changes: 1 addition & 2 deletions crates/oapi-macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -584,8 +584,7 @@ mod tests {
}
impl<'__macro_gen_ex> salvo::Extractible<'__macro_gen_ex> for PetQuery {
fn metadata() -> &'__macro_gen_ex salvo::extract::Metadata {
static METADATA: salvo::__private::once_cell::sync::OnceCell<salvo::extract::Metadata> =
salvo::__private::once_cell::sync::OnceCell::new();
static METADATA: ::std::sync::OnceLock<salvo::extract::Metadata> = ::std::sync::OnceLock::new();
METADATA.get_or_init(||
salvo::extract::Metadata::new("PetQuery")
.default_sources(vec![salvo::extract::metadata::Source::new(
Expand Down
2 changes: 1 addition & 1 deletion crates/oapi-macros/src/parameter/derive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ impl TryToTokens for ToParameters {
}
impl #ex_impl_generics #salvo::Extractible<'__macro_gen_ex> for #ident #ty_generics #where_clause {
fn metadata() -> &'__macro_gen_ex #salvo::extract::Metadata {
static METADATA: #salvo::__private::once_cell::sync::OnceCell<#salvo::extract::Metadata> = #salvo::__private::once_cell::sync::OnceCell::new();
static METADATA: ::std::sync::OnceLock<#salvo::extract::Metadata> = ::std::sync::OnceLock::new();
METADATA.get_or_init(||
#salvo::extract::Metadata::new(#name)
.default_sources(vec![#default_source])
Expand Down
1 change: 0 additions & 1 deletion crates/oapi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ futures-util = { workspace = true }
indexmap = { workspace = true, features = ["serde"] }
inventory = { workspace = true }
mime-infer = { workspace = true }
once_cell = { workspace = true }
parking_lot = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true }
Expand Down
6 changes: 3 additions & 3 deletions crates/oapi/docs/derive_to_response.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,9 @@ _`ToResponse`_ can be used in four different ways to generate OpenAPI response c
[primitive Rust types][primitive], `application/octet-stream` for _`[u8]`_ and
_`application/json`_ for struct and complex enum types.
Content type can also be slice of **content_type** values if the endpoint support returning multiple
response content types. E.g _`["application/json", "text/xml"]`_ would indicate that endpoint can return both
_`json`_ and _`xml`_ formats. **The order** of the content types define the default example show first in
the Swagger UI. Swagger UI will use the first _`content_type`_ value as a default example.
response content types. E.g _`["application/json", "text/xml"]`_ would indicate that endpoint can return both
_`json`_ and _`xml`_ formats. **The order** of the content types define the default example show first in
the Swagger UI. Swagger UI will use the first _`content_type`_ value as a default example.

* `headers(...)` Slice of response headers that are returned back to a caller.

Expand Down
6 changes: 3 additions & 3 deletions crates/oapi/docs/derive_to_responses.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ It can also be overridden with _`description = "..."`_ attribute.
[primitive Rust types][primitive], `application/octet-stream` for _`[u8]`_ and
_`application/json`_ for struct and complex enum types.
Content type can also be slice of **content_type** values if the endpoint support returning multiple
response content types. E.g _`["application/json", "text/xml"]`_ would indicate that endpoint can return both
_`json`_ and _`xml`_ formats. **The order** of the content types define the default example show first in
the Swagger UI. Swagger UI will use the first _`content_type`_ value as a default example.
response content types. E.g _`["application/json", "text/xml"]`_ would indicate that endpoint can return both
_`json`_ and _`xml`_ formats. **The order** of the content types define the default example show first in
the Swagger UI. Swagger UI will use the first _`content_type`_ value as a default example.

* `headers(...)` Slice of response headers that are returned back to a caller.

Expand Down
6 changes: 3 additions & 3 deletions crates/oapi/docs/endpoint.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,9 @@ _**Example request body definitions.**_
[primitive Rust types][primitive], `application/octet-stream` for _`[u8]`_ and
_`application/json`_ for struct and complex enum types.
Content type can also be slice of **content_type** values if the endpoint support returning multiple
response content types. E.g _`["application/json", "text/xml"]`_ would indicate that endpoint can return both
_`json`_ and _`xml`_ formats. **The order** of the content types define the default example show first in
the Swagger UI. Swagger UI will use the first _`content_type`_ value as a default example.
response content types. E.g _`["application/json", "text/xml"]`_ would indicate that endpoint can return both
_`json`_ and _`xml`_ formats. **The order** of the content types define the default example show first in
the Swagger UI. Swagger UI will use the first _`content_type`_ value as a default example.

* `headers(...)` Slice of response headers that are returned back to a caller.

Expand Down
6 changes: 3 additions & 3 deletions crates/oapi/src/naming.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::any::TypeId;
use std::collections::BTreeMap;
use std::sync::LazyLock;

use once_cell::sync::Lazy;
use parking_lot::{RwLock, RwLockReadGuard};
use regex::Regex;

Expand All @@ -15,8 +15,8 @@ pub enum NameRule {
Force(&'static str),
}

static GLOBAL_NAMER: Lazy<RwLock<Box<dyn Namer>>> = Lazy::new(|| RwLock::new(Box::new(FlexNamer::new())));
static NAME_TYPES: Lazy<RwLock<BTreeMap<String, (TypeId, &'static str)>>> = Lazy::new(Default::default);
static GLOBAL_NAMER: LazyLock<RwLock<Box<dyn Namer>>> = LazyLock::new(|| RwLock::new(Box::new(FlexNamer::new())));
static NAME_TYPES: LazyLock<RwLock<BTreeMap<String, (TypeId, &'static str)>>> = LazyLock::new(Default::default);

/// Set global namer.
///
Expand Down
6 changes: 3 additions & 3 deletions crates/oapi/src/openapi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,9 @@ pub mod server;
mod tag;
mod xml;

use crate::{routing::NormNode, Endpoint};
use std::collections::{btree_map, BTreeSet};
use std::sync::LazyLock;

use once_cell::sync::Lazy;
use regex::Regex;
use salvo_core::{async_trait, writing, Depot, FlowCtrl, Handler, Router};
use serde::{de::Visitor, Deserialize, Serialize, Serializer};
Expand All @@ -44,8 +43,9 @@ pub use self::{
tag::Tag,
xml::Xml,
};
use crate::{routing::NormNode, Endpoint};

static PATH_PARAMETER_NAME_REGEX: Lazy<Regex> = Lazy::new(|| Regex::new(r"\{([^}:]+)").expect("invalid regex"));
static PATH_PARAMETER_NAME_REGEX: LazyLock<Regex> = LazyLock::new(|| Regex::new(r"\{([^}:]+)").expect("invalid regex"));

/// The structure of the internal storage object paths.
#[cfg(not(feature = "preserve-path-order"))]
Expand Down
5 changes: 2 additions & 3 deletions crates/oapi/src/routing.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use std::any::TypeId;
use std::collections::{BTreeSet, HashMap};
use std::sync::RwLock;
use std::sync::{LazyLock, RwLock};

use once_cell::sync::Lazy;
use regex::Regex;
use salvo_core::Router;

Expand Down Expand Up @@ -76,7 +75,7 @@ impl NormNode {

/// A component for save router metadata.
type MetadataMap = RwLock<HashMap<usize, Metadata>>;
static METADATA_REGISTRY: Lazy<MetadataMap> = Lazy::new(MetadataMap::default);
static METADATA_REGISTRY: LazyLock<MetadataMap> = LazyLock::new(MetadataMap::default);

/// Router extension trait for openapi metadata.
pub trait RouterExt {
Expand Down
1 change: 0 additions & 1 deletion crates/rate-limiter/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ tokio = { workspace = true }
[dev-dependencies]
salvo_core = { workspace = true, features = ["test"] }
tokio = { workspace = true, features = ["macros", "rt-multi-thread"] }
once_cell = { workspace = true }

[lints]
workspace = true
6 changes: 3 additions & 3 deletions crates/rate-limiter/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,8 @@ where
#[cfg(test)]
mod tests {
use std::collections::HashMap;
use std::sync::LazyLock;

use once_cell::sync::Lazy;
use salvo_core::prelude::*;
use salvo_core::test::{ResponseExt, TestClient};
use salvo_core::Error;
Expand All @@ -250,7 +250,7 @@ mod tests {

#[tokio::test]
async fn test_fixed_dynmaic_quota() {
static USER_QUOTAS: Lazy<HashMap<String, BasicQuota>> = Lazy::new(|| {
static USER_QUOTAS: LazyLock<HashMap<String, BasicQuota>> = LazyLock::new(|| {
let mut map = HashMap::new();
map.insert("user1".into(), BasicQuota::per_second(1));
map.insert("user2".into(), BasicQuota::set_seconds(1, 5));
Expand Down Expand Up @@ -330,7 +330,7 @@ mod tests {

#[tokio::test]
async fn test_sliding_dynmaic_quota() {
static USER_QUOTAS: Lazy<HashMap<String, CelledQuota>> = Lazy::new(|| {
static USER_QUOTAS: LazyLock<HashMap<String, CelledQuota>> = LazyLock::new(|| {
let mut map = HashMap::new();
map.insert("user1".into(), CelledQuota::per_second(1, 1));
map.insert("user2".into(), CelledQuota::set_seconds(1, 1, 5));
Expand Down
Loading

0 comments on commit 6d4dca5

Please sign in to comment.