actix_bincode/
config.rs

1#![allow(clippy::module_name_repetitions)]
2
3/// The default limit in bytes used when deserializing a request payload.
4/// Set to 256 KiB.
5pub const DEFAULT_LIMIT_BYTES: usize = 262_144; // 256 KiB
6
7/// Config for the extractor  
8///
9///     use actix_bincode::config::BincodeConfig;
10///     use actix_web::App;
11///
12///     let config = BincodeConfig::default();  
13///     
14///     let app = App::new().app_data(config);  
15///
16#[derive(Clone, Copy)]
17pub struct BincodeConfig {
18    /// The maximum size in bytes of a request payload that can be deserialized.
19    ///
20    /// By default set to [`DEFAULT_LIMIT_BYTES`]
21    pub limit: usize,
22
23    /// The default buffer size that gets allocated for single payload.
24    ///
25    /// By default set to same as user set `limit` or [`DEFAULT_LIMIT_BYTES`]
26    ///
27    /// This size may be too much for most payloads,
28    /// but avoids reallocating while reading payload
29    pub buf_size: usize,
30}
31
32#[allow(dead_code)]
33impl BincodeConfig {
34    #[must_use]
35    /// Create new config with given limit
36    pub fn new(limit: usize) -> Self {
37        BincodeConfig {
38            limit,
39            buf_size: limit,
40        }
41    }
42}
43
44impl Default for BincodeConfig {
45    /// A default config with limit of 256 KiB.
46    fn default() -> Self {
47        BincodeConfig {
48            limit: DEFAULT_LIMIT_BYTES,
49            buf_size: DEFAULT_LIMIT_BYTES,
50        }
51    }
52}