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// Re-export delta crates that might be needed by local laws
14pub use verifiable;
15
16/// Example local laws implementation.
17#[cfg(any(test, feature = "test-helpers"))]
18pub mod example;
19/// Macros for local laws.
20mod macros;
21
22/// Local laws error.
23#[derive(Debug, Snafu)]
24#[snafu(display("Local laws validation failed: {reason}"))]
25pub struct LocalLawsError {
26    /// The source of the error.
27    reason: String,
28}
29
30impl LocalLawsError {
31    /// Create a new local laws error with the given reason.
32    pub fn new(reason: impl Into<String>) -> Self {
33        Self {
34            reason: reason.into(),
35        }
36    }
37}
38
39/// Local laws trait.
40pub trait LocalLaws {
41    /// The input type for the local laws.
42    type Input<'a>: Serialize + Deserialize<'a>;
43
44    /// Validate the local laws.
45    fn validate<'a>(
46        verifiables: &[VerifiableWithDiffs],
47        verification_context: &VerificationContext,
48        input: &Self::Input<'a>,
49    ) -> Result<(), LocalLawsError>;
50}