Skip to main content

spongefish_circuit/
error.rs

1//! The error of [`PermutationRelation::compile`][crate::PermutationRelation::compile].
2
3use alloc::string::String;
4use core::fmt;
5
6/// A relation that does not describe a valid instance.
7///
8/// Raised by [`PermutationRelation::compile`][crate::PermutationRelation::compile],
9/// the one gate through which a relation becomes a
10/// [`PermutationInstance`][crate::PermutationInstance]. Building a relation
11/// never fails; the checks run here.
12#[derive(Clone, Debug, PartialEq, Eq)]
13pub struct InvalidRelation {
14    message: String,
15}
16
17impl InvalidRelation {
18    pub(crate) fn new(message: impl Into<String>) -> Self {
19        Self {
20            message: message.into(),
21        }
22    }
23
24    /// What was wrong with the relation.
25    pub fn message(&self) -> &str {
26        &self.message
27    }
28}
29
30impl fmt::Display for InvalidRelation {
31    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
32        write!(f, "invalid relation: {}", self.message)
33    }
34}
35
36impl core::error::Error for InvalidRelation {}