1
0
Fork 0
mirror of synced 2025-09-23 12:18:44 +00:00
ZoKrates/zokrates_core/src/macros.rs
2020-12-20 20:30:40 +01:00

36 lines
884 B
Rust

use std::fmt;
use zokrates_field::Field;
use zokrates_pest_ast::File;
#[derive(Debug)]
pub enum Error {
Curve(String, String),
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
Error::Curve(expected, found) => write!(
f,
"When processing macros: curve `{}` is incompatible with curve `{}`",
found, expected
),
}
}
}
pub fn process_macros<T: Field>(file: File) -> Result<File, Error> {
match &file.pragma {
Some(pragma) => {
if T::name() != pragma.curve.name {
Err(Error::Curve(
T::name().to_string(),
pragma.curve.name.clone(),
))
} else {
Ok(file)
}
}
None => Ok(file),
}
}