Skip to content

Commit

Permalink
Added Default for Option.
Browse files Browse the repository at this point in the history
commit-id:2bddf7db
  • Loading branch information
orizi committed Jun 30, 2024
1 parent cb117f9 commit 57017ca
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
6 changes: 6 additions & 0 deletions corelib/src/option.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ pub enum Option<T> {
None,
}

impl OptionDefault<T> of Default<Option<T>> {
fn default() -> Option<T> {
Option::None
}
}

pub impl DestructOption<T, +Destruct<T>, -Drop<Option<T>>> of Destruct<Option<T>> {
#[inline(always)]
fn destruct(self: Option<T>) nopanic {
Expand Down
9 changes: 9 additions & 0 deletions corelib/src/test/option_test.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,12 @@ fn test_option_some_is_none() {
fn test_option_none_is_none() {
assert!(Option::<felt252>::None.is_none());
}

#[derive(Drop)]
struct NonCopy {}

#[test]
fn test_default_for_option() {
assert!(Default::<Option<felt252>>::default().is_none());
assert!(Default::<Option<NonCopy>>::default().is_none());
}

0 comments on commit 57017ca

Please sign in to comment.