Skip to content

Commit

Permalink
chore: deprecate from_fn
Browse files Browse the repository at this point in the history
  • Loading branch information
robjtede committed Aug 10, 2024
1 parent 79306b6 commit 5ec1f08
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 2 deletions.
1 change: 1 addition & 0 deletions actix-web-lab/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

- Implement `Clone` for `extract::Path<T: Clone>`.
- The `Deref` implementation for `header::CacheControl` now returns a slice instead of a `Vec`.
- Deprecate `middleware::from_fn()` now it has graduated to Actix Web.
- Deprecate `extract::ThinData` now it has graduated to Actix Web.

## 0.21.0
Expand Down
2 changes: 2 additions & 0 deletions actix-web-lab/examples/from_fn.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
//! Shows a couple of ways to use the `from_fn` middleware.
#![allow(deprecated)]

use std::{collections::HashMap, io, rc::Rc, time::Duration};

use actix_web::{
Expand Down
3 changes: 2 additions & 1 deletion actix-web-lab/src/middleware.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
//!
//! Analogous to the `middleware` module in Actix Web.
#[allow(deprecated)]
pub use crate::middleware_from_fn::{from_fn, MiddlewareFn, Next};
pub use crate::{
catch_panic::CatchPanic,
err_handler::ErrorHandlers,
load_shed::LoadShed,
middleware_from_fn::{from_fn, MiddlewareFn, Next},
middleware_map_response::{map_response, MapResMiddleware},
middleware_map_response_body::{map_response_body, MapResBodyMiddleware},
normalize_path::NormalizePath,
Expand Down
6 changes: 5 additions & 1 deletion actix-web-lab/src/middleware_from_fn.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
#![allow(deprecated)]

use std::{
future::Future,
future::{ready, Ready},
marker::PhantomData,
rc::Rc,
Expand All @@ -13,7 +16,7 @@ use actix_web::{
dev::{ServiceRequest, ServiceResponse},
Error, FromRequest,
};
use futures_core::{future::LocalBoxFuture, Future};
use futures_core::future::LocalBoxFuture;

/// Wraps an async function to be used as a middleware.
///
Expand Down Expand Up @@ -78,6 +81,7 @@ use futures_core::{future::LocalBoxFuture, Future};
/// // post-processing
/// }
/// # actix_web::App::new().wrap(actix_web_lab::middleware::from_fn(my_extracting_mw));
#[deprecated(since = "0.22.0", note = "Graduated to Actix Web.")]
pub fn from_fn<F, Es>(mw_fn: F) -> MiddlewareFn<F, Es> {
MiddlewareFn {
mw_fn: Rc::new(mw_fn),
Expand Down
2 changes: 2 additions & 0 deletions actix-web-lab/src/redirect_to_non_www.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,10 @@ mod tests {
};

use super::*;
#[allow(deprecated)]
use crate::middleware::from_fn;

#[allow(deprecated)]
fn test_app() -> App<
impl ServiceFactory<
ServiceRequest,
Expand Down
2 changes: 2 additions & 0 deletions actix-web-lab/src/redirect_to_www.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,10 @@ mod tests {
};

use super::*;
#[allow(deprecated)]
use crate::middleware::from_fn;

#[allow(deprecated)]
fn test_app() -> App<
impl ServiceFactory<
ServiceRequest,
Expand Down

0 comments on commit 5ec1f08

Please sign in to comment.