From 91c373e8cb9cacad8af0e7c6b6d43bbadb0a477d Mon Sep 17 00:00:00 2001 From: chachaleo Date: Mon, 9 Oct 2023 14:37:43 +0700 Subject: [PATCH] addition function nullable is_null --- corelib/src/nullable.cairo | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/corelib/src/nullable.cairo b/corelib/src/nullable.cairo index a7a35fd222d..8fc77416b61 100644 --- a/corelib/src/nullable.cairo +++ b/corelib/src/nullable.cairo @@ -17,6 +17,7 @@ extern fn match_nullable(value: Nullable) -> FromNullableResult nopanic trait NullableTrait { fn deref(self: Nullable) -> T; fn new(value: T) -> Nullable; + fn is_null<+Drop>(self: Nullable) -> bool; } impl NullableImpl of NullableTrait { @@ -29,6 +30,12 @@ impl NullableImpl of NullableTrait { fn new(value: T) -> Nullable { nullable_from_box(BoxTrait::new(value)) } + fn is_null<+Drop>(self: Nullable) -> bool { + match match_nullable(self) { + FromNullableResult::Null => true, + FromNullableResult::NotNull(_) => false, + } + } } impl NullableDefault of Default> {