From 36e918fbe0a3046b2a0b791c2c5ca5359952cb21 Mon Sep 17 00:00:00 2001 From: Tom French Date: Fri, 15 Sep 2023 13:57:12 +0100 Subject: [PATCH] feat: add method on `Circuit` to return assert message --- acir/src/circuit/mod.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/acir/src/circuit/mod.rs b/acir/src/circuit/mod.rs index c6d20dac..d03240af 100644 --- a/acir/src/circuit/mod.rs +++ b/acir/src/circuit/mod.rs @@ -40,6 +40,17 @@ pub struct Circuit { pub assert_messages: Vec<(OpcodeLocation, String)>, } +impl Circuit { + /// Returns the assert message associated with the provided [`OpcodeLocation`]. + /// Returns `None` if no such assert message exists. + pub fn get_assert_message(&self, opcode_location: OpcodeLocation) -> Option<&str> { + self.assert_messages + .iter() + .find(|(loc, _)| *loc == opcode_location) + .map(|(_, message)| message.as_str()) + } +} + #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Serialize, Deserialize)] /// Opcodes are locatable so that callers can /// map opcodes to debug information related to their context.