Skip to content

Commit

Permalink
Use ? operator where I can
Browse files Browse the repository at this point in the history
  • Loading branch information
b-j-roberts committed Mar 11, 2024
1 parent 73172b2 commit 63dd245
Showing 1 changed file with 5 additions and 12 deletions.
17 changes: 5 additions & 12 deletions src/bytes/src/utils.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@ fn format_byte_hex(byte: u8, ref f: Formatter) -> Result<(), Error> {
if byte < 0x10 {
// Add leading zero for single digit numbers
let zero: ByteArray = "0";
let res = Display::fmt(@zero, ref f);
if res.is_err() {
return res;
}
Display::fmt(@zero, ref f)?;
}
Display::fmt(@byte.format_as_byte_array(base), ref f)
}
Expand All @@ -22,10 +19,8 @@ impl BytesDebug of Debug<Bytes> {
fn fmt(self: @Bytes, ref f: Formatter) -> Result<(), Error> {
let mut i: usize = 0;
let prefix: ByteArray = "0x";
let mut res = Display::fmt(@prefix, ref f);
if res.is_err() {
return res;
}
Display::fmt(@prefix, ref f)?;
let mut res: Result<(), Error> = Result::Ok(());
while i < self.size() {
let (new_i, value) = self.read_u8(i);
res = format_byte_hex(value, ref f);
Expand All @@ -42,10 +37,8 @@ impl BytesDisplay of Display<Bytes> {
fn fmt(self: @Bytes, ref f: Formatter) -> Result<(), Error> {
let mut i: usize = 0;
let prefix: ByteArray = "0x";
let mut res = Display::fmt(@prefix, ref f);
if res.is_err() {
return res;
}
Display::fmt(@prefix, ref f)?;
let mut res: Result<(), Error> = Result::Ok(());
while i < self.size() {
let (new_i, value) = self.read_u8(i);
res = format_byte_hex(value, ref f);
Expand Down

0 comments on commit 63dd245

Please sign in to comment.