Skip to content

feat: Automatically coerce bools to numbers#1355

Open
Kn4ughty wants to merge 4 commits into
elkowar:masterfrom
Kn4ughty:int_coecing
Open

feat: Automatically coerce bools to numbers#1355
Kn4ughty wants to merge 4 commits into
elkowar:masterfrom
Kn4ughty:int_coecing

Conversation

@Kn4ughty

@Kn4ughty Kn4ughty commented Jul 19, 2025

Copy link
Copy Markdown

Description

If parsing a DynVal as a number (f64, i64, i32) fails, try to convert to a bool, then return 0 or 1 respectively.

fixes #1353

Usage

This script takes in 1 or 0 to control whether the todo is checked.
:onclick ~/.scripts/todo.py update --id=${id} --checked=${!done*1}`
I could just modify the script but there is probably other uses for different logic.

Additional Notes

I think the as_ functions could be made into a macro like how it is with impl_dynval_from.

It should probably go in the documentation somewhere. I was thinking just under the "simple mathematical operations" dot point but I'm not sure.

Checklist

Please make sure you can check all the boxes that apply to this PR.

  • 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

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] Allow coercing bool to integer for math operations

1 participant