actix / actix-extras
Showing 1 of 6 files from the diff.

@@ -0,0 +1,66 @@
Loading
1 +
use std::{error::Error as StdError, fmt};
2 +
3 +
use actix_web::ResponseError;
4 +
use derive_more::Display;
5 +
6 +
#[derive(Debug, Display)]
7 +
pub(crate) enum InsertErrorKind {
8 +
    #[display(fmt = "{}", _0)]
9 +
    Json(serde_json::Error),
10 +
}
11 +
12 +
impl Into<actix_web::Error> for InsertErrorKind {
13 +
    fn into(self) -> actix_web::Error {
14 +
        match self {
15 +
            InsertErrorKind::Json(err) => err.into(),
16 +
        }
17 +
    }
18 +
}
19 +
20 +
/// Error returned by [`Session::insert`][crate::Session::insert]. Allows access to value that
21 +
/// failed to be inserted.
22 +
pub struct InsertError<T> {
23 +
    pub(crate) value: Option<T>,
24 +
    pub(crate) error: InsertErrorKind,
25 +
}
26 +
27 +
impl<T> InsertError<T> {
28 +
    /// Takes value out of error.
29 +
    ///
30 +
    /// # Panics
31 +
    /// Panics if called more than once.
32 +
    pub fn take_value(&mut self) -> T {
33 +
        self.value
34 +
            .take()
35 +
            .expect("take_value should only be called once")
36 +
    }
37 +
}
38 +
39 +
impl<T> fmt::Debug for InsertError<T> {
40 +
    fn fmt<'a>(&'a self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
41 +
        let mut dbg = f.debug_struct("SessionInsertError");
42 +
43 +
        match &self.value {
44 +
            Some(_) => dbg.field("value", &"Some([value])" as _),
45 +
            None => dbg.field("value", &None::<()> as _),
46 +
        };
47 +
48 +
        dbg.field("error", &self.error).finish()
49 +
    }
50 +
}
51 +
52 +
impl<T> fmt::Display for InsertError<T> {
53 +
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
54 +
        fmt::Display::fmt(&self.error, f)
55 +
    }
56 +
}
57 +
58 +
impl<T: fmt::Debug> StdError for InsertError<T> {
59 +
    fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
60 +
        Some(match &self.error {
61 +
            InsertErrorKind::Json(err) => err,
62 +
        })
63 +
    }
64 +
}
65 +
66 +
impl<T> ResponseError for InsertError<T> {}
Files Coverage
actix-cors/src 87.59%
actix-identity/src 95.96%
actix-redis/src 82.10%
actix-session/src 83.73%
actix-web-httpauth/src 60.59%
actix-protobuf/src/lib.rs 50.00%
Project Totals (30 files) 79.82%
1
comment: false
2

3
coverage:
4
  status:
5
    project:
6
      default:
7
        threshold: 100% # make CI green
8
    patch:
9
      default:
10
        threshold: 100% # make CI green
11

12
# ignore code coverage on following paths
13
ignore:
14
  - "**/tests"
15
  - "**/benches"
16
  - "**/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