delta_local_laws/
lib.rs

1//! # Local Laws
2
3use serde::{
4    Deserialize,
5    Serialize,
6};
7use snafu::prelude::*;
8use verifiable::types::{
9    VerifiableWithDiffs,
10    VerificationContext,
11};
12
13/// Example local laws implementation.
14#[cfg(any(test, feature = "test-helpers"))]
15pub mod example;
16
17/// Local laws error.
18#[derive(Debug, Snafu)]
19#[snafu(display("Local laws validation failed: {reason}"))]
20pub struct LocalLawsError {
21    /// The source of the error.
22    reason: String,
23}
24
25impl LocalLawsError {
26    /// Create a new local laws error with the given reason.
27    pub fn new(reason: impl Into<String>) -> Self {
28        Self {
29            reason: reason.into(),
30        }
31    }
32}
33
34/// Local laws trait.
35pub trait LocalLaws {
36    /// The input type for the local laws.
37    type Input<'a>: Serialize + Deserialize<'a>;
38
39    /// Validate the local laws.
40    fn validate<'a>(
41        verifiables: &[VerifiableWithDiffs],
42        verification_context: &VerificationContext,
43        input: &Self::Input<'a>,
44    ) -> Result<(), LocalLawsError>;
45}