resp_result/config/
resp.rs

1#[allow(unused_imports)]
2use http::header::HeaderName;
3#[allow(unused_imports)]
4use std::borrow::Cow;
5
6#[allow(unused_imports)]
7use crate::owner_leak::OwnerLeaker;
8/// the config of response
9pub trait RespConfig {
10    /// wether write the extra error message into header with the  provided name
11    /// - `Some(_)` enable
12    /// - `None` disable
13    ///
14    /// ## Default
15    /// default is enable with name `extra-error`
16    #[cfg(feature = "extra-error")]
17    fn head_extra_code(&self) -> Option<Cow<'static, str>> {
18        Some("extra-error".into())
19    }
20}
21
22pub(crate) struct InnerRespConfig {
23    #[cfg(feature = "extra-error")]
24    pub(crate) extra_code: Option<HeaderName>,
25}
26
27impl InnerRespConfig {
28    #[allow(unused_variables)]
29    pub fn into_inner<C: RespConfig>(cfg: &C) -> Self {
30        Self {
31            #[cfg(feature = "extra-error")]
32            extra_code: cfg.head_extra_code().leak().map(HeaderName::from_static),
33        }
34    }
35}