Showing 1 of 1 files from the diff.

@@ -129,14 +129,16 @@
Loading
129 129
    pub fn custom_request_replace(
130 130
        mut self,
131 131
        label: &'static str,
132 -
        closure: fn(req: &ServiceRequest) -> String,
132 +
        closure: impl Fn(&ServiceRequest) -> String + 'static + Clone,
133 133
    ) -> Self {
134 134
        let inner = Rc::get_mut(&mut self.0).unwrap();
135 135
136 136
        for tf in inner.format.0.iter_mut() {
137 -
            if let FormatText::CustomLog(inner_label, _inner_closure) = tf {
137 +
            if let FormatText::CustomLog(inner_label, inner_closure) = tf {
138 138
                if inner_label == label {
139 -
                    *tf = FormatText::CustomLog(label.to_string(), Some(closure))
139 +
                    *inner_closure = Some(CustomRequestFn {
140 +
                        inner_fn: Rc::new(closure.clone()),
141 +
                    });
140 142
                };
141 143
            };
142 144
        }
@@ -405,7 +407,7 @@
Loading
405 407
/// A string of text to be logged. This is either one of the data
406 408
/// fields supported by the `Logger`, or a custom `String`.
407 409
#[doc(hidden)]
408 -
#[derive(Clone)]
410 +
#[derive(Debug, Clone)]
409 411
pub enum FormatText {
410 412
    Str(String),
411 413
    Percent,
@@ -421,7 +423,18 @@
Loading
421 423
    RequestHeader(HeaderName),
422 424
    ResponseHeader(HeaderName),
423 425
    EnvironHeader(String),
424 -
    CustomLog(String, Option<fn(req: &ServiceRequest) -> String>),
426 +
    CustomLog(String, Option<CustomRequestFn>),
427 +
}
428 +
429 +
#[derive(Clone)]
430 +
pub struct CustomRequestFn {
431 +
    pub(crate) inner_fn: Rc<dyn Fn(&ServiceRequest) -> String>,
432 +
}
433 +
434 +
impl fmt::Debug for CustomRequestFn {
435 +
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
436 +
        f.write_str("custom log closure fn")
437 +
    }
425 438
}
426 439
427 440
impl FormatText {
@@ -478,7 +491,7 @@
Loading
478 491
    }
479 492
480 493
    fn render_request(&mut self, now: OffsetDateTime, req: &ServiceRequest) {
481 -
        match *self {
494 +
        match &*self {
482 495
            FormatText::RequestLine => {
483 496
                *self = if req.query_string().is_empty() {
484 497
                    FormatText::Str(format!(
@@ -532,7 +545,7 @@
Loading
532 545
            }
533 546
            FormatText::CustomLog(_, closure) => {
534 547
                let s = if let Some(closure) = closure {
535 -
                    FormatText::Str(closure(req))
548 +
                    FormatText::Str((closure.inner_fn)(req))
536 549
                } else {
537 550
                    FormatText::Str("-".to_string())
538 551
                };
Files Coverage
actix-files/src 0.00%
actix-http/src 37.77%
actix-multipart/src 0.00%
actix-web-actors/src 0.00%
awc/src 17.98%
src 87.10%
tests 100.00%
actix-web-codegen/src/route.rs 0.00%
Project Totals (126 files) 53.95%
1
ignore: # ignore codecoverage on following paths
2
  - "**/tests"
3
  - "test-server"
4
  - "**/benches"
5
  - "**/examples"
Sunburst
The inner-most circle is the entire project, moving away from the center are folders then, finally, a single file. The size and color of each slice is representing the number of statements and the coverage, respectively.
Icicle
The top section represents the entire project. Proceeding with folders and finally individual files. The size and color of each slice is representing the number of statements and the coverage, respectively.
Grid
Each block represents a single file in the project. The size and color of each block is represented by the number of statements and the coverage, respectively.
Loading