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

Code before:
    pub fn error_handler<F>(mut self, f: F) -> Self
    where
        F: Fn(UrlencodedError, &HttpRequest) -> Error + 'static,
    {
        self.err_handler = Some(Rc::new(f));
        self
    }

    /// Extract payload config from app data. Check both `T` and `Data<T>`, in that order, and fall
    /// back to the default payload config.
    fn from_req(req: &HttpRequest) -> &Self {
        req.app_data::<Self>()
            .or_else(|| req.app_data::<web::Data<Self>>().map(|d| d.as_ref()))
            .unwrap_or(&DEFAULT_CONFIG)
    }
}

/// Allow shared refs used as default.
const DEFAULT_CONFIG: FormConfig = FormConfig {
    limit: 16_384, // 2^14 bytes (~16kB)
    err_handler: None,
};

impl Default for FormConfig {
    fn default() -> Self {
        DEFAULT_CONFIG.clone()
    }
}

/// Future that resolves to some `T` when parsed from a URL encoded payload.
///
/// Form can be deserialized from any type `T` that implements [`serde::Deserialize`].
///
/// Returns error if:
/// - content type is not `application/x-www-form-urlencoded`
/// - content length is greater than [limit](UrlEncoded::limit())
pub struct UrlEncoded<T> {
    #[cfg(feature = "compress")]
    stream: Option<Decompress<Payload>>,
    #[cfg(not(feature = "compress"))]
    stream: Option<Payload>,

    limit: usize,
    length: Option<usize>,
    encoding: &'static Encoding,
    err: Option<UrlencodedError>,
    fut: Option<LocalBoxFuture<'static, Result<T, UrlencodedError>>>,
}

#[allow(clippy::borrow_interior_mutable_const)]
impl<T> UrlEncoded<T> {

Review comment (suggestion):
This should work without `.clone()`.

```suggestion
        DEFAULT_CONFIG
```

Code after:
        self.limit = limit;
        self
    }

    /// Set custom error handler
    pub fn error_handler<F>(mut self, f: F) -> Self
    where
        F: Fn(UrlencodedError, &HttpRequest) -> Error + 'static,
    {
        self.err_handler = Some(Rc::new(f));
        self
    }

    /// Extract payload config from app data.
    ///
    /// Checks both `T` and `Data<T>`, in that order, and falls back to the default payload config.
    fn from_req(req: &HttpRequest) -> &Self {
        req.app_data::<Self>()
            .or_else(|| req.app_data::<web::Data<Self>>().map(|d| d.as_ref()))
            .unwrap_or(&DEFAULT_CONFIG)
    }
}

/// Allow shared refs used as default.
const DEFAULT_CONFIG: FormConfig = FormConfig {
    limit: 16_384, // 2^14 bytes (~16kB)
    err_handler: None,
};

impl Default for FormConfig {
    fn default() -> Self {
        DEFAULT_CONFIG
    }
}

/// Future that resolves to some `T` when parsed from a URL encoded payload.
///
/// Form can be deserialized from any type `T` that implements [`serde::Deserialize`].
///
/// Returns error if:
/// - content type is not `application/x-www-form-urlencoded`
/// - content length is greater than [limit](UrlEncoded::limit())
pub struct UrlEncoded<T> {
    #[cfg(feature = "__compress")]
    stream: Option<Decompress<Payload>>,
    #[cfg(not(feature = "__compress"))]
    stream: Option<Payload>,

    limit: usize,
    length: Option<usize>,
    encoding: &'static Encoding,