crypto_pay_api/validation/
mod.rs

1use crate::error::CryptoBotResult;
2use crate::models::ExchangeRate;
3use async_trait::async_trait;
4
5pub trait FieldValidate {
6    /// Validate every field of the model without context
7    fn validate(&self) -> CryptoBotResult<()>;
8}
9
10#[async_trait]
11pub trait ContextValidate {
12    /// Validate field of the model with external context
13    async fn validate_with_context(&self, ctx: &ValidationContext) -> CryptoBotResult<()>;
14}
15
16pub struct ValidationContext {
17    pub exchange_rates: Vec<ExchangeRate>,
18}
19
20#[macro_export]
21macro_rules! validate_dependency {
22    ($condition:expr, $field:expr, $message:expr) => {
23        if $condition {
24            return Err(CryptoBotError::ValidationError {
25                kind: ValidationErrorKind::Missing,
26                message: $message.to_string(),
27                field: Some($field.to_string()),
28            });
29        }
30    };
31}
32
33mod amount;
34mod count;
35
36pub use amount::*;
37pub use count::*;