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

Safe Access Operator #577

Merged
merged 7 commits into from
Oct 1, 2022
Merged

Conversation

oldwomanjosiah
Copy link
Contributor

@oldwomanjosiah oldwomanjosiah commented Sep 19, 2022

Description

  • closes [FEATURE] Safe Access Syntax #565
  • Updates the elvis operator ?: to treat a JSON Null the same as the empty string ""
    This was done, as that is what is returned by an object access for an undefined field.

Usage

:label { labels?.workspaces?.one ?: "Workspace One" }

with some varable labels. labels.workspaces.one ?: "Workspace One" would error if:

  • labels was not an object
  • labels.workspaces was not an object

It would also act strangely if either any of labels, .workspaces, or .one were Null, as the elvis operator treated that as "already existing".

Diffs containing full example of usage

Additional Notes

It might also make sense to allow for opt-object?.[key-expr], but that is left for a follow-up.

Checklist

  • All widgets I've added are correctly documented.
  • I added my changes to CHANGELOG.md, if appropriate.
  • The documentation in the docs/content/main directory has been adjusted to reflect my changes.
  • I used cargo fmt to automatically format all code before committing

@oldwomanjosiah oldwomanjosiah marked this pull request as draft September 19, 2022 18:17
@oldwomanjosiah oldwomanjosiah marked this pull request as ready for review September 19, 2022 18:24
@elkowar
Copy link
Owner

elkowar commented Oct 1, 2022

thanks a lot for your work! This is cool!

@elkowar elkowar merged commit 37fc231 into elkowar:master Oct 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[FEATURE] Safe Access Syntax
2 participants