From 3144c009b63dae959a3af43afe97f896692dd82f Mon Sep 17 00:00:00 2001 From: Ori Ziv Date: Sun, 30 Jun 2024 12:22:39 +0300 Subject: [PATCH] Added `Default` for `Option`. commit-id:2bddf7db --- corelib/src/option.cairo | 6 ++++++ corelib/src/test/option_test.cairo | 9 +++++++++ 2 files changed, 15 insertions(+) diff --git a/corelib/src/option.cairo b/corelib/src/option.cairo index 6db7b302bb1..431db7661c3 100644 --- a/corelib/src/option.cairo +++ b/corelib/src/option.cairo @@ -5,6 +5,12 @@ pub enum Option { None, } +impl OptionDefault of Default> { + fn default() -> Option { + Option::None + } +} + pub impl DestructOption, -Drop>> of Destruct> { #[inline(always)] fn destruct(self: Option) nopanic { diff --git a/corelib/src/test/option_test.cairo b/corelib/src/test/option_test.cairo index 89a60a2bf96..0ebab0185f2 100644 --- a/corelib/src/test/option_test.cairo +++ b/corelib/src/test/option_test.cairo @@ -59,3 +59,12 @@ fn test_option_some_is_none() { fn test_option_none_is_none() { assert!(Option::::None.is_none()); } + +#[derive(Drop)] +struct NonCopy {} + +#[test] +fn test_default_for_option() { + assert!(Default::>::default().is_none()); + assert!(Default::>::default().is_none()); +}