diff --git a/Cargo.lock b/Cargo.lock index fa015c8534..e782717790 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -863,20 +863,6 @@ dependencies = [ "typenum", ] -[[package]] -name = "dashmap" -version = "6.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5041cc499144891f3790297212f32a74fb938e5136a14943f338ef9e0ae276cf" -dependencies = [ - "cfg-if", - "crossbeam-utils", - "hashbrown 0.14.5", - "lock_api", - "once_cell", - "parking_lot_core", -] - [[package]] name = "data-encoding" version = "2.9.0" @@ -1487,12 +1473,6 @@ dependencies = [ "byteorder", ] -[[package]] -name = "hashbrown" -version = "0.14.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" - [[package]] name = "hashbrown" version = "0.15.5" @@ -1985,7 +1965,6 @@ dependencies = [ "actix-http", "actix-web", "any_spawner", - "dashmap", "futures", "hydration_context", "leptos", @@ -1993,7 +1972,6 @@ dependencies = [ "leptos_macro", "leptos_meta", "leptos_router", - "parking_lot", "send_wrapper", "serde_json", "server_fn", @@ -2008,7 +1986,6 @@ version = "0.8.6" dependencies = [ "any_spawner", "axum", - "dashmap", "futures", "hydration_context", "leptos", @@ -2016,7 +1993,6 @@ dependencies = [ "leptos_macro", "leptos_meta", "leptos_router", - "parking_lot", "server_fn", "tachys", "tokio", @@ -2063,7 +2039,6 @@ dependencies = [ "anyhow", "camino", "indexmap", - "parking_lot", "proc-macro2", "quote", "rstml", @@ -2943,7 +2918,6 @@ name = "reactive_stores" version = "0.3.0" dependencies = [ "any_spawner", - "dashmap", "guardian", "itertools", "leptos", @@ -3476,7 +3450,6 @@ dependencies = [ "ciborium", "const-str", "const_format", - "dashmap", "futures", "gloo-net", "http 1.3.1", @@ -3808,7 +3781,6 @@ dependencies = [ "next_tuple", "oco_ref", "or_poisoned", - "parking_lot", "paste", "reactive_graph", "reactive_stores", diff --git a/Cargo.toml b/Cargo.toml index 0da0001c1a..15b6d3cfee 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -89,7 +89,6 @@ actix-web = { default-features = false, version = "4.11.0" } tracing = { default-features = false, version = "0.1.41" } slotmap = { default-features = false, version = "1.0.7" } futures = { default-features = false, version = "0.3.31" } -dashmap = { default-features = false, version = "6.1.0" } pin-project-lite = { default-features = false, version = "0.2.16" } send_wrapper = { default-features = false, version = "0.6.0" } tokio-test = { default-features = false, version = "0.4.4" } @@ -105,7 +104,6 @@ wasm-bindgen-futures = { default-features = false, version = "0.4.50" } tower = { default-features = false, version = "0.5.2" } proc-macro2 = { default-features = false, version = "1.0.101" } serde = { default-features = false, version = "1.0.219" } -parking_lot = { default-features = false, version = "0.12.5" } axum = { default-features = false, version = "0.8.6" } serde_qs = { default-features = false, version = "0.15.0" } syn = { default-features = false, version = "2.0.106" } diff --git a/examples/server_fns_axum/Cargo.toml b/examples/server_fns_axum/Cargo.toml index c7a9abb5fb..808390c0ad 100644 --- a/examples/server_fns_axum/Cargo.toml +++ b/examples/server_fns_axum/Cargo.toml @@ -37,7 +37,6 @@ web-sys = { version = "0.3.70", features = ["FileList", "File"] } strum = { version = "0.27.1", features = ["strum_macros", "derive"] } notify = { version = "8.0", optional = true } pin-project-lite = "0.2.14" -dashmap = { version = "6.0", optional = true } async-broadcast = { version = "0.7.1", optional = true } bytecheck = "0.8.0" rkyv = { version = "0.8.8" } @@ -52,7 +51,6 @@ ssr = [ "leptos/ssr", "dep:leptos_axum", "dep:notify", - "dep:dashmap", "dep:async-broadcast", ] diff --git a/examples/server_fns_axum/src/app.rs b/examples/server_fns_axum/src/app.rs index f81a38921b..665925a7cb 100644 --- a/examples/server_fns_axum/src/app.rs +++ b/examples/server_fns_axum/src/app.rs @@ -422,7 +422,8 @@ pub fn FileUploadWithProgress() -> impl IntoView { #[cfg(feature = "ssr")] mod progress { use async_broadcast::{broadcast, Receiver, Sender}; - use dashmap::DashMap; + use std::collections::HashMap; + use std::sync::Mutex; use futures::Stream; use std::sync::LazyLock; @@ -432,13 +433,14 @@ pub fn FileUploadWithProgress() -> impl IntoView { rx: Receiver, } - static FILES: LazyLock> = - LazyLock::new(DashMap::new); + static FILES: LazyLock>> = + LazyLock::new(|| Mutex::new(HashMap::new())); pub async fn add_chunk(filename: &str, len: usize) { println!("[{filename}]\tadding {len}"); + let files = FILES.lock().unwrap(); let mut entry = - FILES.entry(filename.to_string()).or_insert_with(|| { + files.entry(filename.to_string()).or_insert_with(|| { println!("[{filename}]\tinserting channel"); let (tx, rx) = broadcast(128); File { total: 0, tx, rx } @@ -457,8 +459,9 @@ pub fn FileUploadWithProgress() -> impl IntoView { } pub fn for_file(filename: &str) -> impl Stream { + let files = FILES.lock().unwrap(); let entry = - FILES.entry(filename.to_string()).or_insert_with(|| { + files.entry(filename.to_string()).or_insert_with(|| { println!("[{filename}]\tinserting channel"); let (tx, rx) = broadcast(128); File { total: 0, tx, rx } diff --git a/integrations/actix/Cargo.toml b/integrations/actix/Cargo.toml index bb6b2908c4..040bfa2c8c 100644 --- a/integrations/actix/Cargo.toml +++ b/integrations/actix/Cargo.toml @@ -23,11 +23,9 @@ leptos_router = { workspace = true, features = ["ssr"] } server_fn = { workspace = true, features = ["actix-no-default"] } tachys = { workspace = true } serde_json = { workspace = true, default-features = true } -parking_lot = { workspace = true, default-features = true } tracing = { optional = true, workspace = true, default-features = true } tokio = { features = ["rt", "fs"], workspace = true, default-features = true } send_wrapper = { workspace = true, default-features = true } -dashmap = { workspace = true, default-features = true } [package.metadata.docs.rs] rustdoc-args = ["--generate-link-to-definition"] diff --git a/integrations/actix/src/lib.rs b/integrations/actix/src/lib.rs index aa1fe0ef10..2408738198 100644 --- a/integrations/actix/src/lib.rs +++ b/integrations/actix/src/lib.rs @@ -16,7 +16,6 @@ use actix_web::{ web::{Data, Payload, ServiceConfig}, *, }; -use dashmap::DashMap; use futures::{stream::once, Stream, StreamExt}; use http::StatusCode; use hydration_context::SsrSharedContext; @@ -38,19 +37,18 @@ use leptos_router::{ static_routes::{RegenerationFn, ResolvedStaticPath}, ExpandOptionals, Method, PathSegment, RouteList, RouteListing, SsrMode, }; -use parking_lot::RwLock; use send_wrapper::SendWrapper; use server_fn::{ error::ServerFnErrorErr, redirect::REDIRECT_HEADER, request::actix::ActixRequest, }; use std::{ - collections::HashSet, + collections::{HashMap, HashSet}, fmt::{Debug, Display}, future::Future, ops::{Deref, DerefMut}, path::Path, - sync::{Arc, LazyLock}, + sync::{Arc, LazyLock, RwLock}, }; /// This struct lets you define headers and override the status of the Response from an Element or a Server Function @@ -121,12 +119,12 @@ pub struct ResponseOptions(pub Arc>); impl ResponseOptions { /// A simpler way to overwrite the contents of `ResponseOptions` with a new `ResponseParts`. pub fn overwrite(&self, parts: ResponseParts) { - let mut writable = self.0.write(); + let mut writable = self.0.write().unwrap(); *writable = parts } /// Set the status of the returned Response. pub fn set_status(&self, status: StatusCode) { - let mut writeable = self.0.write(); + let mut writeable = self.0.write().unwrap(); let res_parts = &mut *writeable; res_parts.status = Some(status); } @@ -136,7 +134,7 @@ impl ResponseOptions { key: header::HeaderName, value: header::HeaderValue, ) { - let mut writeable = self.0.write(); + let mut writeable = self.0.write().unwrap(); let res_parts = &mut *writeable; res_parts.headers.insert(key, value); } @@ -146,7 +144,7 @@ impl ResponseOptions { key: header::HeaderName, value: header::HeaderValue, ) { - let mut writeable = self.0.write(); + let mut writeable = self.0.write().unwrap(); let res_parts = &mut *writeable; res_parts.headers.append(key, value); } @@ -170,7 +168,7 @@ impl ExtendResponse for ActixResponse { } fn extend_response(&mut self, res_options: &Self::ResponseOptions) { - let mut res_options = res_options.0.write(); + let mut res_options = res_options.0.write().unwrap(); let headers = self.0.headers_mut(); for (key, value) in std::mem::take(&mut res_options.headers) { @@ -394,7 +392,8 @@ pub fn handle_server_fns_with_context( // the Location header may have been set to Referer, so any redirection by the // user must overwrite it { - let mut res_options = res_options.0.write(); + let mut res_options = + res_options.0.write().unwrap(); let headers = res.0.headers_mut(); for location in @@ -1222,12 +1221,12 @@ impl StaticRouteGenerator { } } -static STATIC_HEADERS: LazyLock> = - LazyLock::new(DashMap::new); +static STATIC_HEADERS: LazyLock>> = + LazyLock::new(|| RwLock::new(HashMap::new())); fn was_404(owner: &Owner) -> bool { let resp = owner.with(|| expect_context::()); - let status = resp.0.read().status; + let status = resp.0.read().unwrap().status; if let Some(status) = status { return status == StatusCode::NOT_FOUND; @@ -1255,7 +1254,10 @@ async fn write_static_route( html: &str, ) -> Result<(), std::io::Error> { if let Some(options) = response_options { - STATIC_HEADERS.insert(path.to_string(), options); + STATIC_HEADERS + .write() + .unwrap() + .insert(path.to_string(), options); } let path = static_path(options, path); @@ -1322,8 +1324,10 @@ where .await; (owner.with(use_context::), html) } else { - let headers = - STATIC_HEADERS.get(orig_path).map(|v| v.clone()); + let headers = STATIC_HEADERS + .read() + .unwrap() + .get(orig_path).cloned(); (headers, None) }; diff --git a/integrations/axum/Cargo.toml b/integrations/axum/Cargo.toml index 3e1edd697d..b5878f88f8 100644 --- a/integrations/axum/Cargo.toml +++ b/integrations/axum/Cargo.toml @@ -14,7 +14,6 @@ hydration_context = { workspace = true } axum = { default-features = false, features = [ "matched-path", ], workspace = true } -dashmap = { workspace = true, default-features = true } futures = { workspace = true, default-features = true } leptos = { workspace = true, features = ["nonce", "ssr"] } server_fn = { workspace = true, features = ["axum-no-default"] } @@ -23,7 +22,6 @@ leptos_meta = { workspace = true, features = ["ssr", "nonce"] } leptos_router = { workspace = true, features = ["ssr"] } leptos_integration_utils = { workspace = true } tachys = { workspace = true } -parking_lot = { workspace = true, default-features = true } tokio = { default-features = false, workspace = true } tower = { features = ["util"], workspace = true, default-features = true } tower-http = { workspace = true, default-features = true } diff --git a/integrations/axum/src/lib.rs b/integrations/axum/src/lib.rs index 0930134d12..7385b87f55 100644 --- a/integrations/axum/src/lib.rs +++ b/integrations/axum/src/lib.rs @@ -47,8 +47,6 @@ use axum::{ response::IntoResponse, routing::{delete, get, patch, post, put}, }; -#[cfg(feature = "default")] -use dashmap::DashMap; use futures::{stream::once, Future, Stream, StreamExt}; use hydration_context::SsrSharedContext; use leptos::{ @@ -69,12 +67,15 @@ use leptos_router::{ static_routes::RegenerationFn, ExpandOptionals, PathSegment, RouteList, RouteListing, SsrMode, }; -use parking_lot::RwLock; use server_fn::{error::ServerFnErrorErr, redirect::REDIRECT_HEADER}; #[cfg(feature = "default")] +use std::collections::HashMap; +#[cfg(feature = "default")] use std::path::Path; #[cfg(feature = "default")] use std::sync::LazyLock; +use std::sync::RwLock; +#[cfg(feature = "default")] use std::{collections::HashSet, fmt::Debug, io, pin::Pin, sync::Arc}; #[cfg(feature = "default")] use tower::util::ServiceExt; @@ -126,24 +127,24 @@ pub struct ResponseOptions(pub Arc>); impl ResponseOptions { /// A simpler way to overwrite the contents of `ResponseOptions` with a new `ResponseParts`. pub fn overwrite(&self, parts: ResponseParts) { - let mut writable = self.0.write(); + let mut writable = self.0.write().unwrap(); *writable = parts } /// Set the status of the returned Response. pub fn set_status(&self, status: StatusCode) { - let mut writeable = self.0.write(); + let mut writeable = self.0.write().unwrap(); let res_parts = &mut *writeable; res_parts.status = Some(status); } /// Insert a header, overwriting any previous value with the same key. pub fn insert_header(&self, key: HeaderName, value: HeaderValue) { - let mut writeable = self.0.write(); + let mut writeable = self.0.write().unwrap(); let res_parts = &mut *writeable; res_parts.headers.insert(key, value); } /// Append a header, leaving any header with the same key intact. pub fn append_header(&self, key: HeaderName, value: HeaderValue) { - let mut writeable = self.0.write(); + let mut writeable = self.0.write().unwrap(); let res_parts = &mut *writeable; res_parts.headers.append(key, value); } @@ -166,7 +167,7 @@ impl ExtendResponse for AxumResponse { } fn extend_response(&mut self, res_options: &Self::ResponseOptions) { - let mut res_options = res_options.0.write(); + let mut res_options = res_options.0.write().unwrap(); if let Some(status) = res_options.status { *self.0.status_mut() = status; } @@ -1522,13 +1523,13 @@ impl StaticRouteGenerator { } #[cfg(feature = "default")] -static STATIC_HEADERS: LazyLock> = - LazyLock::new(DashMap::new); +static STATIC_HEADERS: LazyLock>> = + LazyLock::new(|| RwLock::new(HashMap::new())); #[cfg(feature = "default")] fn was_404(owner: &Owner) -> bool { let resp = owner.with(|| expect_context::()); - let status = resp.0.read().status; + let status = resp.0.read().unwrap().status; if let Some(status) = status { return status == StatusCode::NOT_FOUND; @@ -1558,7 +1559,10 @@ async fn write_static_route( html: &str, ) -> Result<(), std::io::Error> { if let Some(options) = response_options { - STATIC_HEADERS.insert(path.to_string(), options); + STATIC_HEADERS + .write() + .unwrap() + .insert(path.to_string(), options); } let path = static_path(options, path); @@ -1635,7 +1639,11 @@ where .await; (owner.with(use_context::), html) } else { - let headers = STATIC_HEADERS.get(orig_path).map(|v| v.clone()); + let headers = STATIC_HEADERS + .read() + .unwrap() + .get(orig_path) + .map(|v| v.clone()); (headers, None) }; diff --git a/leptos_hot_reload/Cargo.toml b/leptos_hot_reload/Cargo.toml index f2103b2995..4c999c1b87 100644 --- a/leptos_hot_reload/Cargo.toml +++ b/leptos_hot_reload/Cargo.toml @@ -25,7 +25,6 @@ proc-macro2 = { features = [ "span-locations", "nightly", ], workspace = true, default-features = true } -parking_lot = { workspace = true, default-features = true } walkdir = { workspace = true, default-features = true } camino = { workspace = true, default-features = true } indexmap = { workspace = true, default-features = true } diff --git a/leptos_hot_reload/src/lib.rs b/leptos_hot_reload/src/lib.rs index 1f186851b9..d5ae8adc4e 100644 --- a/leptos_hot_reload/src/lib.rs +++ b/leptos_hot_reload/src/lib.rs @@ -4,14 +4,13 @@ use anyhow::Result; use camino::Utf8PathBuf; use diff::Patches; use node::LNode; -use parking_lot::RwLock; use serde::{Deserialize, Serialize}; use std::{ collections::HashMap, fs::File, io::Read, path::{Path, PathBuf}, - sync::Arc, + sync::{Arc, RwLock}, }; use syn::{ spanned::Spanned, @@ -58,7 +57,7 @@ impl ViewMacros { } } - *self.views.write() = views; + *self.views.write().unwrap() = views; Ok(()) } @@ -101,7 +100,7 @@ impl ViewMacros { /// Will return `Err` if the contents of the file cannot be parsed. pub fn patch(&self, path: &Utf8PathBuf) -> Result> { let new_views = Self::parse_file(path)?; - let mut lock = self.views.write(); + let mut lock = self.views.write().unwrap(); let diffs = match lock.get(path) { None => return Ok(None), Some(current_views) => { diff --git a/reactive_stores/Cargo.toml b/reactive_stores/Cargo.toml index fcf9d2fc0d..d0922e66df 100644 --- a/reactive_stores/Cargo.toml +++ b/reactive_stores/Cargo.toml @@ -17,7 +17,6 @@ paste = { workspace = true, default-features = true } reactive_graph = { workspace = true } rustc-hash = { workspace = true, default-features = true } reactive_stores_macro = { workspace = true } -dashmap = { workspace = true, default-features = true } send_wrapper = { workspace = true, default-features = true } [dev-dependencies] diff --git a/reactive_stores/src/lib.rs b/reactive_stores/src/lib.rs index 9c0d8b8241..27877cbbc8 100644 --- a/reactive_stores/src/lib.rs +++ b/reactive_stores/src/lib.rs @@ -415,7 +415,7 @@ impl Default for FieldKeys { } #[cfg(not(target_arch = "wasm32"))] -type HashMap = Arc>; +type HashMap = Arc>>; #[cfg(target_arch = "wasm32")] type HashMap = send_wrapper::SendWrapper< std::rc::Rc>>, @@ -453,8 +453,9 @@ impl KeyMap { let initial_keys = initialize(); #[cfg(not(target_arch = "wasm32"))] - let mut entry = self - .0 + let mut map_0 = self.0.lock().unwrap(); + #[cfg(not(target_arch = "wasm32"))] + let entry = map_0 .entry(path.clone()) .or_insert_with(|| Box::new(FieldKeys::new(initial_keys))); @@ -471,13 +472,26 @@ impl KeyMap { let entry = entry.downcast_mut::>()?; let (result, new_keys) = fun(entry); + + #[cfg(not(target_arch = "wasm32"))] + drop(map_0); + + let mut map_1 = { + #[cfg(not(target_arch = "wasm32"))] + { + self.1.lock().unwrap() + } + + #[cfg(target_arch = "wasm32")] + { + self.1.borrow_mut() + } + }; + if !new_keys.is_empty() { for (idx, segment) in new_keys { - #[cfg(not(target_arch = "wasm32"))] - self.1.insert((path.clone(), idx), segment); - - #[cfg(target_arch = "wasm32")] - self.1.borrow_mut().insert((path.clone(), idx), segment); + map_1.insert((path.clone(), idx), segment); + map_1.insert((path.clone(), idx), segment); } } Some(result) @@ -486,7 +500,7 @@ impl KeyMap { fn contains_key(&self, key: &StorePath) -> bool { #[cfg(not(target_arch = "wasm32"))] { - self.0.contains_key(key) + self.0.lock().unwrap().contains_key(key) } #[cfg(target_arch = "wasm32")] @@ -501,7 +515,7 @@ impl KeyMap { ) -> Option { #[cfg(not(target_arch = "wasm32"))] { - self.1.get(key).as_deref().copied() + self.1.lock().unwrap().get(key).copied() } #[cfg(target_arch = "wasm32")] diff --git a/server_fn/Cargo.lock b/server_fn/Cargo.lock index 016d65bf39..95452a101e 100644 --- a/server_fn/Cargo.lock +++ b/server_fn/Cargo.lock @@ -558,19 +558,6 @@ dependencies = [ "typenum", ] -[[package]] -name = "dashmap" -version = "5.5.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "978747c1d849a7d2ee5e8adc0159961c48fb7e5db2f06af6723b80123bb53856" -dependencies = [ - "cfg-if", - "hashbrown 0.14.3", - "lock_api", - "once_cell", - "parking_lot_core", -] - [[package]] name = "deranged" version = "0.3.10" @@ -1829,7 +1816,6 @@ dependencies = [ "bytes", "ciborium", "const_format", - "dashmap", "futures", "gloo-net", "http 1.0.0", diff --git a/server_fn/Cargo.toml b/server_fn/Cargo.toml index 35c2fc9b44..7e213783af 100644 --- a/server_fn/Cargo.toml +++ b/server_fn/Cargo.toml @@ -28,7 +28,6 @@ thiserror = { workspace = true, default-features = true } # registration system inventory = { optional = true, workspace = true, default-features = true } -dashmap = { workspace = true, default-features = true } ## servers # actix diff --git a/server_fn/src/lib.rs b/server_fn/src/lib.rs index 3e52d1da91..a0438e2d89 100644 --- a/server_fn/src/lib.rs +++ b/server_fn/src/lib.rs @@ -145,7 +145,6 @@ use codec::{Encoding, FromReq, FromRes, IntoReq, IntoRes}; pub use const_format; #[doc(hidden)] pub use const_str; -use dashmap::DashMap; pub use error::ServerFnError; #[cfg(feature = "form-redirects")] use error::ServerFnUrlError; @@ -165,12 +164,13 @@ pub use serde; pub use serde_lite; use server::Server; use std::{ + collections::HashMap, fmt::{Debug, Display}, future::Future, marker::PhantomData, ops::{Deref, DerefMut}, pin::Pin, - sync::{Arc, LazyLock}, + sync::{Arc, LazyLock, RwLock}, }; #[doc(hidden)] pub use xxhash_rust; @@ -866,12 +866,14 @@ pub use inventory; macro_rules! initialize_server_fn_map { ($req:ty, $res:ty) => { std::sync::LazyLock::new(|| { - $crate::inventory::iter::> + let map = $crate::inventory::iter::> .into_iter() .map(|obj| { ((obj.path().to_string(), obj.method()), obj.clone()) }) - .collect() + .collect(); + + std::sync::RwLock::new(map) }) }; } @@ -984,7 +986,7 @@ impl Clone for ServerFnTraitObj { #[allow(unused)] // used by server integrations type LazyServerFnMap = - LazyLock>>; + LazyLock>>>; #[cfg(feature = "ssr")] impl inventory::Collect @@ -1066,7 +1068,7 @@ pub mod axum { >, > + 'static, { - REGISTERED_SERVER_FUNCTIONS.insert( + REGISTERED_SERVER_FUNCTIONS.write().unwrap().insert( (T::PATH.into(), T::Protocol::METHOD), ServerFnTraitObj::new::(|req| Box::pin(T::run_on_server(req))), ); @@ -1074,9 +1076,14 @@ pub mod axum { /// The set of all registered server function paths. pub fn server_fn_paths() -> impl Iterator { - REGISTERED_SERVER_FUNCTIONS - .iter() + let paths: Vec<_> = REGISTERED_SERVER_FUNCTIONS + .read() + .unwrap() + .values() .map(|item| (item.path(), item.method())) + .collect(); + + paths.into_iter() } /// An Axum handler that responds to a server function request. @@ -1110,14 +1117,18 @@ pub mod axum { method: Method, ) -> Option, Response>> { let key = (path.into(), method); - REGISTERED_SERVER_FUNCTIONS.get(&key).map(|server_fn| { - let middleware = (server_fn.middleware)(); - let mut service = server_fn.clone().boxed(); - for middleware in middleware { - service = middleware.layer(service); - } - service - }) + REGISTERED_SERVER_FUNCTIONS + .read() + .unwrap() + .get(&key) + .map(|server_fn| { + let middleware = (server_fn.middleware)(); + let mut service = server_fn.clone().boxed(); + for middleware in middleware { + service = middleware.layer(service); + } + service + }) } } @@ -1177,7 +1188,7 @@ pub mod actix { >, > + 'static, { - REGISTERED_SERVER_FUNCTIONS.insert( + REGISTERED_SERVER_FUNCTIONS.write().unwrap().insert( (T::PATH.into(), T::Protocol::METHOD), ServerFnTraitObj::new::(|req| Box::pin(T::run_on_server(req))), ); @@ -1185,9 +1196,14 @@ pub mod actix { /// The set of all registered server function paths. pub fn server_fn_paths() -> impl Iterator { - REGISTERED_SERVER_FUNCTIONS - .iter() + let paths: Vec<_> = REGISTERED_SERVER_FUNCTIONS + .read() + .unwrap() + .values() .map(|item| (item.path(), item.method())) + .collect(); + + paths.into_iter() } /// An Actix handler that responds to a server function request. @@ -1236,16 +1252,19 @@ pub mod actix { ActixMethod::CONNECT => Method::CONNECT, _ => unreachable!(), }; - REGISTERED_SERVER_FUNCTIONS.get(&(path.into(), method)).map( - |server_fn| { + + REGISTERED_SERVER_FUNCTIONS + .read() + .unwrap() + .get(&(path.into(), method)) + .map(|server_fn| { let middleware = (server_fn.middleware)(); let mut service = server_fn.clone().boxed(); for middleware in middleware { service = middleware.layer(service); } service - }, - ) + }) } } diff --git a/tachys/Cargo.toml b/tachys/Cargo.toml index aa75106e38..82adcb01d1 100644 --- a/tachys/Cargo.toml +++ b/tachys/Cargo.toml @@ -152,7 +152,6 @@ drain_filter_polyfill = { workspace = true, default-features = true } indexmap = { workspace = true, default-features = true } rustc-hash = { workspace = true, default-features = true } futures = { workspace = true, default-features = true } -parking_lot = { workspace = true, default-features = true } itertools = { workspace = true, default-features = true } send_wrapper = { workspace = true, default-features = true } linear-map = { workspace = true, default-features = true } diff --git a/tachys/src/view/mod.rs b/tachys/src/view/mod.rs index ad1e0f43df..86cfbdfa2e 100644 --- a/tachys/src/view/mod.rs +++ b/tachys/src/view/mod.rs @@ -3,8 +3,12 @@ use crate::{ html::attribute::any_attribute::AnyAttribute, hydration::Cursor, ssr::StreamBuilder, }; -use parking_lot::RwLock; -use std::{cell::RefCell, future::Future, rc::Rc, sync::Arc}; +use std::{ + cell::RefCell, + future::Future, + rc::Rc, + sync::{Arc, RwLock}, +}; /// Add attributes to typed views. pub mod add_attr; @@ -476,12 +480,12 @@ impl PositionState { /// Sets the current position. pub fn set(&self, position: Position) { - *self.0.write() = position; + *self.0.write().unwrap() = position; } /// Gets the current position. pub fn get(&self) -> Position { - *self.0.read() + *self.0.read().unwrap() } /// Creates a new [`PositionState`], which starts with the same [`Position`], but no longer