serialize and deserialize impls

This commit is contained in:
Aravinth Manivannan 2021-03-12 13:52:49 +05:30
parent 46f318482f
commit 95f1272e11
Signed by: realaravinth
GPG key ID: AD9F0F08E855ED88
5 changed files with 10 additions and 7 deletions

View file

@ -1,2 +1,3 @@
# 0.1.1 # 0.1.1
- typo fix: `MCaptcha::decrement_visiotr()` became `MCaptcha::decrement_visitor()` - typo fix: `MCaptcha::decrement_visiotr()` became `MCaptcha::decrement_visitor()`
- `serde::{Serialize, Deserialize}` impls (shouldn't break anything)

2
Cargo.lock generated
View file

@ -570,7 +570,7 @@ dependencies = [
[[package]] [[package]]
name = "m_captcha" name = "m_captcha"
version = "0.1.0" version = "0.1.1"
dependencies = [ dependencies = [
"actix", "actix",
"actix-rt", "actix-rt",

3
src/cache/mod.rs vendored
View file

@ -31,13 +31,14 @@ pub mod messages {
//! Messages that can be sent to cache data structures implementing [Save][super::Save] //! Messages that can be sent to cache data structures implementing [Save][super::Save]
use actix::dev::*; use actix::dev::*;
use derive_builder::Builder; use derive_builder::Builder;
use serde::{Deserialize, Serialize};
use crate::errors::*; use crate::errors::*;
use crate::mcaptcha::VisitorResult; use crate::mcaptcha::VisitorResult;
use crate::pow::PoWConfig; use crate::pow::PoWConfig;
/// Message to cache PoW difficulty factor and string /// Message to cache PoW difficulty factor and string
#[derive(Message, Builder)] #[derive(Message, Serialize, Deserialize, Builder)]
#[rtype(result = "CaptchaResult<()>")] #[rtype(result = "CaptchaResult<()>")]
pub struct Cache { pub struct Cache {
pub string: String, pub string: String,

View file

@ -43,9 +43,10 @@
//! ``` //! ```
use crate::errors::*; use crate::errors::*;
use serde::{Deserialize, Serialize};
/// Level struct that describes threshold-difficulty factor mapping /// Level struct that describes threshold-difficulty factor mapping
#[derive(Debug, Copy, Clone, PartialEq)] #[derive(Debug, Deserialize, Serialize, Copy, Clone, PartialEq)]
pub struct Level { pub struct Level {
visitor_threshold: u32, visitor_threshold: u32,
difficulty_factor: u32, difficulty_factor: u32,
@ -106,7 +107,7 @@ impl LevelBuilder {
} }
/// struct describes all the different [Level]s at which an mCaptcha system operates /// struct describes all the different [Level]s at which an mCaptcha system operates
#[derive(Debug, Clone, PartialEq)] #[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
pub struct Defense { pub struct Defense {
levels: Vec<Level>, levels: Vec<Level>,
// index of current visitor threshold // index of current visitor threshold

View file

@ -18,12 +18,12 @@
//! PoW datatypes used in client-server interaction //! PoW datatypes used in client-server interaction
use pow_sha256::PoW; use pow_sha256::PoW;
use serde::Serialize; use serde::{Deserialize, Serialize};
pub use pow_sha256::ConfigBuilder; pub use pow_sha256::ConfigBuilder;
/// PoW requirement datatype that is be sent to clients for generating PoW /// PoW requirement datatype that is be sent to clients for generating PoW
#[derive(Clone, Serialize, Debug)] #[derive(Clone, Serialize, Deserialize, Debug)]
pub struct PoWConfig { pub struct PoWConfig {
pub string: String, pub string: String,
pub difficulty_factor: u32, pub difficulty_factor: u32,
@ -41,7 +41,7 @@ impl PoWConfig {
} }
/// PoW datatype that clients send to server /// PoW datatype that clients send to server
#[derive(Clone, Serialize, Debug)] #[derive(Clone, Serialize, Deserialize, Debug)]
pub struct Work { pub struct Work {
pub string: String, pub string: String,
pub result: String, pub result: String,