-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Bool: Add to_unsafe
#5465
Bool: Add to_unsafe
#5465
Conversation
I'd prefer the naming |
I think that @woodruffw his to_i is more clear to understand. The to_unsafe is a keyword is better left to actions that really are unsafe. |
I agree with @RX14 -- |
Has the added benefit of allowing you to pass boolean variables into functions without conversion - the to_unsafe is automatic. |
probably better let compiler accept boolean in c binding |
src/bool.cr
Outdated
@@ -46,6 +46,11 @@ struct Bool | |||
hasher.bool(self) | |||
end | |||
|
|||
# Returns `1` for `true` and `0` for `false`. | |||
def to_i |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You renamed the PR but didn't push new code?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's weird, I thought I did. Pushed it now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check again.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wow, that was stupid of me. I amended the commit but didn't actually re-add my changes. Sorry about that.
`Bool.to_unsafe` returns `1` for `true` and `0` for false.
There's nothing unsafe from going from |
@asterite I agree there's noting unsafe about going Also implementing Bool in C bindings is weird to me, as bool isn't a datatype in C, it's only implemented as an integer. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's go with this for now
Introduces
Bool.to_unsafe
, which returns1
fortrue
and0
for false.This comes in handy when calling C bindings that take a
bool
-ish integer, and is clearer thanBool.hash
(which also changed in0.24.1
):