actix_msgpack/
msgpack_config.rs1use super::{ErrorHandler, DEFAULT_PAYLOAD_LIMIT};
2use crate::{ContentTypeHandler, MsgPackError};
3use actix_web::{error::Error, HttpRequest};
4use mime::Mime;
5use std::sync::Arc;
6
7#[derive(Clone)]
8pub struct MsgPackConfig {
9 pub(crate) limit: usize,
10 pub(crate) error_handler: Option<ErrorHandler>,
11 pub(crate) content_type: Option<ContentTypeHandler>,
12}
13
14pub const DEFAULT_CONFIG: MsgPackConfig =
15 MsgPackConfig { limit: DEFAULT_PAYLOAD_LIMIT, error_handler: None, content_type: None };
16
17impl MsgPackConfig {
18 pub fn limit(&mut self, limit: usize) -> &mut Self {
20 self.limit = limit;
21 self
22 }
23
24 pub fn error_handler<F>(&mut self, handler: F) -> &mut Self
25 where
26 F: Fn(MsgPackError, &HttpRequest) -> Error + Send + Sync + 'static,
27 {
28 self.error_handler = Some(Arc::new(handler));
29 self
30 }
31
32 pub fn content_type<F>(&mut self, handler: F) -> &mut Self
34 where
35 F: Fn(Mime) -> bool + Send + Sync + 'static,
36 {
37 self.content_type = Some(Arc::new(handler));
38 self
39 }
40}
41
42impl Default for MsgPackConfig {
43 fn default() -> Self {
44 DEFAULT_CONFIG
45 }
46}