Skip to content

Commit

Permalink
Merge pull request #35 from ym-project/issue-34
Browse files Browse the repository at this point in the history
#34 Allow to change config without using `mut`
  • Loading branch information
ym-project authored Jun 23, 2024
2 parents d36e8db + bd5105c commit b6687e0
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
26 changes: 24 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ mod tests {
use super::*;
use actix_web::body::MessageBody;
use actix_web::http::{header, StatusCode};
use actix_web::test::TestRequest;
use actix_web::test::{init_service, TestRequest};
use actix_web::web::Bytes;
use actix_web::{HttpRequest, HttpResponse, Responder};
use actix_web::{App, HttpRequest, HttpResponse, Responder};
use mime::{APPLICATION_JSON, APPLICATION_MSGPACK};
use serde::{Deserialize, Serialize};

Expand Down Expand Up @@ -241,4 +241,26 @@ mod tests {
vec![0x81, 0xa7, 0x70, 0x61, 0x79, 0x6c, 0x6f, 0x61, 0x64, 0xc3]
);
}

#[allow(unused_variables, unused_mut, clippy::assertions_on_constants)]
#[actix_web::test]
async fn check_config_defining() {
//
// The point of tests is to make sure the compiler doesn't show errors
//

// Create config inside app_data with custom limit
let app1 = init_service(App::new().app_data(MsgPackConfig::default().limit(0))).await;

// Create config with custom limit
let config2 = MsgPackConfig::default().limit(0);
let app2 = init_service(App::new().app_data(config2)).await;

// Create mutable config with custom limit
let mut config3 = MsgPackConfig::default();
config3.limit(0);
let app3 = init_service(App::new().app_data(config3)).await;

assert!(true);
}
}
3 changes: 2 additions & 1 deletion src/msgpack_config.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
use super::DEFAULT_PAYLOAD_LIMIT;

#[derive(Clone, Copy)]
pub struct MsgPackConfig {
pub(crate) limit: usize,
}

impl MsgPackConfig {
/// Set maximum accepted payload size in bytes. The default limit is 256KiB.
pub fn limit(&mut self, limit: usize) -> &mut Self {
pub fn limit(mut self, limit: usize) -> Self {
self.limit = limit;
self
}
Expand Down

0 comments on commit b6687e0

Please sign in to comment.