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

addition function nullable is_null #4232

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
7 changes: 7 additions & 0 deletions corelib/src/nullable.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ extern fn match_nullable<T>(value: Nullable<T>) -> FromNullableResult<T> nopanic
trait NullableTrait<T> {
fn deref(self: Nullable<T>) -> T;
fn new(value: T) -> Nullable<T>;
fn is_null<+Drop<T>>(self: Nullable<T>) -> bool;
}

impl NullableImpl<T> of NullableTrait<T> {
Expand All @@ -29,6 +30,12 @@ impl NullableImpl<T> of NullableTrait<T> {
fn new(value: T) -> Nullable<T> {
nullable_from_box(BoxTrait::new(value))
}
fn is_null<+Drop<T>>(self: Nullable<T>) -> bool {
match match_nullable(self) {
FromNullableResult::Null => true,
FromNullableResult::NotNull(_) => false,
}
}
}

impl NullableDefault<T> of Default<Nullable<T>> {
Expand Down