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: add try_deref method for NullableTrait<T> #5666

Open
tdelabro opened this issue May 28, 2024 · 0 comments
Open

feat: add try_deref method for NullableTrait<T> #5666

tdelabro opened this issue May 28, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@tdelabro
Copy link
Contributor

tdelabro commented May 28, 2024

Feature Request

There is a deref that panic, there is a deref_or that takes a default value, but we could easily add a try_deref that would return an Option<T>.

Describe Alternatives

Using the TryInto trait: imp TryNullableTIntoT<T> of TryInto<Nullable<T>, T>.

Related code

pub impl NullableImpl<T> of NullableTrait<T> {
fn deref(self: Nullable<T>) -> T {
match match_nullable(self) {
FromNullableResult::Null => core::panic_with_felt252('Attempted to deref null value'),
FromNullableResult::NotNull(value) => value.unbox(),
}
}
fn deref_or<+Drop<T>>(self: Nullable<T>, default: T) -> T {
match match_nullable(self) {
FromNullableResult::Null => default,
FromNullableResult::NotNull(value) => value.unbox(),
}
}

If the feature request is approved, would you be willing to submit a PR?
(Help can be provided if you need assistance submitting a PR)

No, it can be an easy task for a new contributor

@tdelabro tdelabro added the enhancement New feature or request label May 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant