1use std::net::IpAddr;
2
3use crate::CaptchaToken;
4
5#[derive(Debug)]
7#[non_exhaustive]
8pub struct VerificationRequest {
9 token: CaptchaToken,
11 remote_ip: Option<IpAddr>,
13}
14
15impl VerificationRequest {
16 #[must_use]
18 pub const fn new(token: CaptchaToken) -> Self {
19 Self {
20 token,
21 remote_ip: None,
22 }
23 }
24
25 #[must_use]
27 pub const fn token(&self) -> &CaptchaToken {
28 &self.token
29 }
30
31 #[must_use]
33 pub const fn remote_ip(&self) -> Option<IpAddr> {
34 self.remote_ip
35 }
36
37 #[must_use]
39 pub const fn with_remote_ip(mut self, remote_ip: IpAddr) -> Self {
40 self.remote_ip = Some(remote_ip);
41 self
42 }
43}
44
45#[cfg(test)]
46mod tests {
47 use super::VerificationRequest;
48 use crate::CaptchaToken;
49
50 #[test]
51 fn request_preserves_the_supplied_token() {
52 let raw_token = "request-preservation-test-token";
53 let token = CaptchaToken::new(raw_token).expect("token should be valid");
54
55 let request = VerificationRequest::new(token);
56
57 assert_eq!(request.token().expose(), raw_token);
58 }
59}