From 1b5961edaabba63a9dd71009fc86e6e902563908 Mon Sep 17 00:00:00 2001 From: Greg Johnston Date: Fri, 26 Jan 2024 17:54:42 -0500 Subject: [PATCH] fix: fix type inference on `extract()` functions (#2233) --- integrations/actix/src/lib.rs | 6 ++---- integrations/axum/src/lib.rs | 20 ++++++-------------- 2 files changed, 8 insertions(+), 18 deletions(-) diff --git a/integrations/actix/src/lib.rs b/integrations/actix/src/lib.rs index da756fe275..b5fb97b611 100644 --- a/integrations/actix/src/lib.rs +++ b/integrations/actix/src/lib.rs @@ -1390,15 +1390,13 @@ impl LeptosRoutes for &mut ServiceConfig { /// Ok(data) /// } /// ``` -pub async fn extract() -> Result> +pub async fn extract() -> Result where T: actix_web::FromRequest, ::Error: Display, { let req = use_context::().ok_or_else(|| { - ServerFnError::ServerError( - "HttpRequest should have been provided via context".to_string(), - ) + ServerFnError::new("HttpRequest should have been provided via context") })?; T::extract(&req) diff --git a/integrations/axum/src/lib.rs b/integrations/axum/src/lib.rs index 7e53762c7f..61c9ba46eb 100644 --- a/integrations/axum/src/lib.rs +++ b/integrations/axum/src/lib.rs @@ -55,10 +55,7 @@ use leptos_router::*; use once_cell::sync::OnceCell; use parking_lot::RwLock; use server_fn::redirect::REDIRECT_HEADER; -use std::{ - error::Error, fmt::Debug, io, pin::Pin, sync::Arc, - thread::available_parallelism, -}; +use std::{fmt::Debug, io, pin::Pin, sync::Arc, thread::available_parallelism}; use tokio_util::task::LocalPoolHandle; use tracing::Instrument; @@ -1772,13 +1769,12 @@ fn get_leptos_pool() -> LocalPoolHandle { /// Ok(query) /// } /// ``` -pub async fn extract() -> Result +pub async fn extract() -> Result where T: Sized + FromRequestParts<()>, T::Rejection: Debug, - CustErr: Error + 'static, { - extract_with_state::(&()).await + extract_with_state::(&()).await } /// A helper to make it easier to use Axum extractors in server functions. This @@ -1800,18 +1796,14 @@ where /// Ok(query) /// } /// ``` -pub async fn extract_with_state( - state: &S, -) -> Result +pub async fn extract_with_state(state: &S) -> Result where T: Sized + FromRequestParts, T::Rejection: Debug, - CustErr: Error + 'static, { let mut parts = use_context::().ok_or_else(|| { - ServerFnError::ServerError::( - "should have had Parts provided by the leptos_axum integration" - .to_string(), + ServerFnError::new( + "should have had Parts provided by the leptos_axum integration", ) })?; T::from_request_parts(&mut parts, state)