replace pub(crate) to pub in ServiceConfig::new() (#250)

This commit is contained in:
RuangyotN 2025-03-25 10:00:56 +07:00
parent 91caca1272
commit 8cf00fc5a0

View file

@ -68,7 +68,7 @@ pub struct ServiceConfig<Err = DefaultError> {
}
impl<Err: ErrorRenderer> ServiceConfig<Err> {
pub(crate) fn new() -> Self {
pub fn new() -> Self {
Self {
services: Vec::new(),
state: Extensions::new(),
@ -124,26 +124,6 @@ impl<Err: ErrorRenderer> ServiceConfig<Err> {
self.external.push(rdef);
self
}
/// Creates a new instance of [`ServiceConfig`] for use in custom application configurations.
///
/// This is an alternative constructor to [`ServiceConfig::new()`], intended for
/// external crates and libraries that require access to [`ServiceConfig`] outside the crate scope.
///
/// # Examples
///
/// ```rust
/// use ntex::web::{ServiceConfig, DefaultError};
///
/// let config: ServiceConfig<DefaultError> = ServiceConfig::register();
/// ```
pub fn register() -> Self {
Self {
services: Vec::new(),
state: Extensions::new(),
external: Vec::new(),
}
}
}
#[cfg(test)]
@ -227,8 +207,8 @@ mod tests {
}
#[test]
fn test_service_config_register() {
let cfg: ServiceConfig<DefaultError> = ServiceConfig::register();
fn test_new_service_config() {
let cfg: ServiceConfig<DefaultError> = ServiceConfig::new();
assert!(cfg.services.is_empty());
assert!(cfg.external.is_empty());
}