From 5a64f69ef3e3611129a4b34a076a9fc843d75135 Mon Sep 17 00:00:00 2001 From: Ori Ziv Date: Thu, 26 Sep 2024 15:37:28 +0300 Subject: [PATCH] Allow defining const negative `NonZero`. commit-id:790154f7 --- corelib/src/zeroable.cairo | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/corelib/src/zeroable.cairo b/corelib/src/zeroable.cairo index 8685bf09c35..41d7c45c5bd 100644 --- a/corelib/src/zeroable.cairo +++ b/corelib/src/zeroable.cairo @@ -76,6 +76,14 @@ pub(crate) impl Felt252Zeroable = zero_based::ZeroableImpl; /// This type guarantees that the wrapped value is never zero. #[derive(Copy, Drop)] pub extern type NonZero; +impl NonZeroNeg, +TryInto>> of Neg> { + fn neg(a: NonZero) -> NonZero { + // TODO(orizi): Optimize using bounded integers. + let value: T = a.into(); + let negated: T = -value; + negated.try_into().unwrap() + } +} /// Represents the result of checking whether a value is zero. pub(crate) enum IsZeroResult {