Repository: actix/actix-web
File: src/app.rs (Rust)

Code before:
    ///     let app = App::new()
    ///         .data(MyData{ counter: Cell::new(0) })
    ///         .service(
    ///             web::resource("/index.html").route(
    ///                 web::get().to(index)));
    /// }
    /// ```
    pub fn data<S: 'static>(mut self, data: S) -> Self {
        self.data.push(Box::new(Data::new(data)));
        self
    }

    /// Set application data factory. This function is
    /// similar to `.data()` but it accepts data factory. Data object get
    /// constructed asynchronously during application initialization.
    pub fn data_factory<F, R>(mut self, data: F) -> Self
    where
        F: Fn() -> R + 'static,
        R: IntoFuture + 'static,
        R::Error: std::fmt::Debug,
    {
        self.data.push(Box::new(data));
        self
    }

    /// Registers heavyweight Application-level middleware, in the form of a
    /// re-usable middleware type, that runs during inbound and/or outbound 
    /// processing in the request lifecycle (request -> response).
    ///
    /// ```rust
    /// use actix_service::Service;
    /// # use futures::Future;
    /// use actix_web::{middleware, web, App};
    /// use actix_web::http::{header::CONTENT_TYPE, HeaderValue};
    ///
    /// fn index() -> &'static str {
    ///     "Welcome!"
    /// }
    ///
    /// fn main() {
    ///     let app = App::new()
    ///         .wrap(middleware::Logger::default())
    ///         .route("/index.html", web::get().to(index));
    /// }
    /// ```
    pub fn wrap<M, B, F>(
        self,
        mw: F,
    ) -> AppRouter<
        T,
        Out,

Review comment (refactor):
i am not sure about `heavyweight` and `lightweight`. should we maybe use extra info for clarification. something like "in form of reusable components", and "in-place request/response modification".
i expect at some point `wrap` and `wrap_fn` will be merged together, but at the moment rust's type inference is not powerful enough for that.

Code after:
    ///     let app = App::new()
    ///         .data(MyData{ counter: Cell::new(0) })
    ///         .service(
    ///             web::resource("/index.html").route(
    ///                 web::get().to(index)));
    /// }
    /// ```
    pub fn data<S: 'static>(mut self, data: S) -> Self {
        self.data.push(Box::new(Data::new(data)));
        self
    }

    /// Set application data factory. This function is
    /// similar to `.data()` but it accepts data factory. Data object get
    /// constructed asynchronously during application initialization.
    pub fn data_factory<F, R>(mut self, data: F) -> Self
    where
        F: Fn() -> R + 'static,
        R: IntoFuture + 'static,
        R::Error: std::fmt::Debug,
    {
        self.data.push(Box::new(data));
        self
    }

    /// Registers middleware, in the form of a middleware component (type), 
    /// that runs during inbound and/or outbound processing in the request 
    /// lifecycle (request -> response), modifying request/response as 
    /// necessary, across all requests managed by the *Application*.
    ///
    /// Use middleware when you need to read or modify *every* request or response in some way.
    ///
    /// ```rust
    /// use actix_service::Service;
    /// # use futures::Future;
    /// use actix_web::{middleware, web, App};
    /// use actix_web::http::{header::CONTENT_TYPE, HeaderValue};
    ///
    /// fn index() -> &'static str {
    ///     "Welcome!"
    /// }
    ///
    /// fn main() {
    ///     let app = App::new()
    ///         .wrap(middleware::Logger::default())
    ///         .route("/index.html", web::get().to(index));
    /// }
    /// ```
    pub fn wrap<M, B, F>(
        self,
        mw: F,