From 82088715b454d8cf197b9c54c31525ca0cb57a05 Mon Sep 17 00:00:00 2001 From: JChoy Date: Sat, 31 Aug 2024 04:02:38 +0900 Subject: [PATCH] feat: implement Display trait for i257 (#327) ## Pull Request type Please check the type of change your PR introduces: - [ ] Bugfix - [x] Feature - [ ] Code style update (formatting, renaming) - [ ] Refactoring (no functional changes, no API changes) - [ ] Build-related changes - [ ] Documentation content changes - [ ] Other (please describe): ## What is the current behavior? Issue Number: N/A ## What is the new behavior? - Implemented Display trait for `i257` ## Does this introduce a breaking change? - [ ] Yes - [x] No ## Other information --- packages/math/src/i257.cairo | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/packages/math/src/i257.cairo b/packages/math/src/i257.cairo index 694f2cac..325c5796 100644 --- a/packages/math/src/i257.cairo +++ b/packages/math/src/i257.cairo @@ -1,3 +1,4 @@ +use core::fmt::{Display, Formatter, Error}; use core::num::traits::Zero; use core::ops::{AddAssign, SubAssign, MulAssign, DivAssign, RemAssign}; @@ -353,3 +354,14 @@ impl FeltIntoI257 of Into { i257 { abs: self.into(), is_negative: false } } } + +// Implements the Display trait for i257. +pub impl DisplayI257Impl of Display { + fn fmt(self: @i257, ref f: Formatter) -> Result<(), Error> { + if *self.is_negative { + write!(f, "-")?; + } + self.abs.fmt(ref f) + } +} +