Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Default impls for signed integer types #5312

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions corelib/src/integer.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -1738,6 +1738,40 @@ impl U256Default of Default<u256> {
}
}

impl I8Default of Default<i8> {
#[inline(always)]
fn default() -> i8 nopanic {
0_i8
}
}

impl I16Default of Default<i16> {
#[inline(always)]
fn default() -> i16 nopanic {
0_i16
}
}

impl I32Default of Default<i32> {
#[inline(always)]
fn default() -> i32 nopanic {
0_i32
}
}

impl I64Default of Default<i64> {
#[inline(always)]
fn default() -> i64 nopanic {
0_i64
}
}

impl I128Default of Default<i128> {
#[inline(always)]
fn default() -> i128 nopanic {
0_i128
}
}

/// Default values for felt252_dict values.
impl U8Felt252DictValue of Felt252DictValue<u8> {
Expand Down
5 changes: 5 additions & 0 deletions corelib/src/test/integer_test.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -886,6 +886,11 @@ fn test_default_values() {
assert_eq(@Default::default(), @0_u64, '0 == 0');
assert_eq(@Default::default(), @0_u128, '0 == 0');
assert_eq(@Default::default(), @0_u256, '0 == 0');
assert_eq(@Default::default(), @0_i8, '0 == 0');
assert_eq(@Default::default(), @0_i16, '0 == 0');
assert_eq(@Default::default(), @0_i32, '0 == 0');
assert_eq(@Default::default(), @0_i64, '0 == 0');
assert_eq(@Default::default(), @0_i128, '0 == 0');
}

#[test]
Expand Down
Loading