Skip to content

Commit ebd08be

Browse files
authored
Merge pull request #256 from H1rono/parser-arc-inner
♻️ Wrap `RequestParser`'s inner with `Arc`
2 parents 2050dd7 + 1362d04 commit ebd08be

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

src/lib.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,16 @@ pub mod payloads;
1818
#[cfg(feature = "tower")]
1919
pub mod handler;
2020

21+
use std::sync::Arc;
22+
2123
pub use error::{Error, ErrorKind, Result};
2224
pub use events::{Event, EventKind};
2325

2426
/// HTTP POSTリクエストのパーサー
2527
#[must_use]
2628
#[derive(Debug, Clone)]
2729
pub struct RequestParser {
28-
verification_token: String,
30+
inner: Arc<parser::Inner>,
2931
}
3032

3133
#[cfg(feature = "tower")]

src/parser.rs

+16-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//! `struct RequestParser`の定義
22
33
use std::str::from_utf8;
4+
use std::sync::Arc;
45

56
use crate::error::{Error, ErrorKind, Result};
67
use crate::macros::all_events;
@@ -37,6 +38,19 @@ fn valid_header_value(value: &str) -> bool {
3738
.all(|c| (0x20..=0x7E).contains(c) || *c == 0x09)
3839
}
3940

41+
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
42+
pub(crate) struct Inner {
43+
verification_token: String,
44+
}
45+
46+
impl Inner {
47+
pub(crate) fn new(verification_token: &str) -> Self {
48+
Self {
49+
verification_token: verification_token.to_string(),
50+
}
51+
}
52+
}
53+
4054
impl RequestParser {
4155
/// 新しい`RequestParser`を作成します。
4256
///
@@ -50,7 +64,7 @@ impl RequestParser {
5064
/// ```
5165
pub fn new(verification_token: &str) -> Self {
5266
Self {
53-
verification_token: verification_token.to_string(),
67+
inner: Arc::new(Inner::new(verification_token)),
5468
}
5569
}
5670

@@ -142,7 +156,7 @@ impl RequestParser {
142156
.then_some(t)
143157
.ok_or(ErrorKind::ReadBotTokenFailed)
144158
})
145-
.map(|t| t == self.verification_token)?
159+
.map(|t| t == self.inner.verification_token)?
146160
.then_some(())
147161
.ok_or(ErrorKind::BotTokenMismatch)?;
148162
kind.ok_or(ErrorKind::BotEventNotFound)

0 commit comments

Comments
 (0)