add async feature #1

Merged
b4tman merged 62 commits from async into master 2023-08-18 06:29:46 +00:00
Showing only changes of commit c061fef267 - Show all commits

View File

@ -1,74 +1,88 @@
use serde_derive::{Deserialize, Serialize}; use serde_derive::{Deserialize, Serialize};
#[derive(Debug, Default, Clone, Serialize, Deserialize, bincode::Decode, bincode::Encode)] #[derive(
Debug, Default, Clone, Serialize, Deserialize, bincode::Decode, bincode::Encode, PartialEq,
)]
pub struct BatchInfo { pub struct BatchInfo {
#[serde(default)] #[serde(default, skip_serializing_if = "String::is_empty")]
pub filename: String, pub filename: String,
#[serde(default)] #[serde(default, skip_serializing_if = "String::is_empty")]
pub description: String, pub description: String,
#[serde(default)] #[serde(default, skip_serializing_if = "String::is_empty")]
pub author: String, pub author: String,
#[serde(default)] #[serde(default, skip_serializing_if = "String::is_empty")]
pub comment: String, pub comment: String,
#[serde(default)] #[serde(default, skip_serializing_if = "String::is_empty")]
pub url: String, pub url: String,
#[serde(default)] #[serde(default, skip_serializing_if = "String::is_empty")]
pub date: String, pub date: String,
#[serde(default)] #[serde(default, skip_serializing_if = "String::is_empty")]
pub processed_by: String, pub processed_by: String,
#[serde(default)] #[serde(default, skip_serializing_if = "String::is_empty")]
pub redacted_by: String, pub redacted_by: String,
#[serde(default)] #[serde(default, skip_serializing_if = "String::is_empty")]
pub copyright: String, pub copyright: String,
#[serde(default)] #[serde(default, skip_serializing_if = "String::is_empty")]
pub theme: String, pub theme: String,
#[serde(default)] #[serde(default, skip_serializing_if = "String::is_empty")]
pub kind: String, pub kind: String,
#[serde(default)] #[serde(default, skip_serializing_if = "String::is_empty")]
pub source: String, pub source: String,
#[serde(default)] #[serde(default, skip_serializing_if = "String::is_empty")]
pub rating: String, pub rating: String,
} }
#[derive(Debug, Default, Clone, Serialize, Deserialize, bincode::Decode, bincode::Encode)] #[derive(
Debug, Default, Clone, Serialize, Deserialize, bincode::Decode, bincode::Encode, PartialEq,
)]
pub struct Question { pub struct Question {
#[serde(default)] #[serde(default, skip_serializing_if = "u32_is_zero")]
pub num: u32, pub num: u32,
pub id: String, pub id: String,
pub description: String, pub description: String,
pub answer: String, pub answer: String,
#[serde(default)] #[serde(default, skip_serializing_if = "String::is_empty")]
pub author: String, pub author: String,
#[serde(default)] #[serde(default, skip_serializing_if = "String::is_empty")]
pub comment: String, pub comment: String,
#[serde(default)] #[serde(default, skip_serializing_if = "String::is_empty")]
pub comment1: String, pub comment1: String,
#[serde(default)] #[serde(default, skip_serializing_if = "String::is_empty")]
pub tour: String, pub tour: String,
#[serde(default)] #[serde(default, skip_serializing_if = "String::is_empty")]
pub url: String, pub url: String,
#[serde(default)] #[serde(default, skip_serializing_if = "String::is_empty")]
pub date: String, pub date: String,
#[serde(default)] #[serde(default, skip_serializing_if = "String::is_empty")]
pub processed_by: String, pub processed_by: String,
#[serde(default)] #[serde(default, skip_serializing_if = "String::is_empty")]
pub redacted_by: String, pub redacted_by: String,
#[serde(default)] #[serde(default, skip_serializing_if = "String::is_empty")]
pub copyright: String, pub copyright: String,
#[serde(default)] #[serde(default, skip_serializing_if = "String::is_empty")]
pub theme: String, pub theme: String,
#[serde(default)] #[serde(default, skip_serializing_if = "String::is_empty")]
pub kind: String, pub kind: String,
#[serde(default)] #[serde(default, skip_serializing_if = "String::is_empty")]
pub source: String, pub source: String,
#[serde(default)] #[serde(default, skip_serializing_if = "String::is_empty")]
pub rating: String, pub rating: String,
#[serde(default)] #[serde(default, skip_serializing_if = "BatchInfo::is_default")]
pub batch_info: BatchInfo, pub batch_info: BatchInfo,
} }
fn u32_is_zero(num: &u32) -> bool {
*num == 0
}
impl BatchInfo {
pub fn is_default(&self) -> bool {
*self == BatchInfo::default()
}
}
#[cfg(any(feature = "convert", feature = "convert_async"))] #[cfg(any(feature = "convert", feature = "convert_async"))]
pub mod convert_common { pub mod convert_common {
use super::{BatchInfo, Question}; use super::{BatchInfo, Question};