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

Non-unsafe functions for PODs #8

Merged
merged 4 commits into from
Oct 14, 2017
Merged

Non-unsafe functions for PODs #8

merged 4 commits into from
Oct 14, 2017

Conversation

nabijaczleweli
Copy link
Owner

@nabijaczleweli nabijaczleweli commented Oct 9, 2017

Working PR, but something concrete at least.

Ref: #5

Effectively just uses a marker trait to waive any responsibility

Also, is #[cfg(stage0)] the correct thingy to enable {i,u}128s with

Ref: #5
Copy link
Collaborator

@Enet4 Enet4 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Things look ok other than the typo, but I'm starting to feel that our function naming and categorization approach won't scale well. As at least 2 variants, sometimes 3 or 6, are created for each case, things may explode quickly. Let's throw in a new issue on this, it's better to change the API sooner than later.

src/pod.rs Outdated
/// Marker trait for `guarded_transmute_pod_*()` functions.
///
/// *Nota bene*: `bool`s aren't *actually* non-`unsafe` to transmute, because they're restricted to being `0` or `1`,
/// which means it's UB to transmute an arbitrary byte to into a `bool`.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"to into"

src/pod.rs Outdated
/// which means it's UB to transmute an arbitrary byte to into a `bool`.
///
/// *Nota bene*: if you transmute into a floating-point type you will have a chance to create signaling NaNs
/// (judgement's still out as to whether they're legal).
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, it's not like they're illegal, but signaling NaNs are usually undesirable here. They can be converted to quiet NaNs in separate functions.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm taking "separate functions" as "user normalises" (because, (a) that's out of scope, and (b) do you know what user wants)?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually meant that we should include it. It has potential use cases (do want), and if the user wants sNaNs anyway, we can invite them to use the unsafe functions.

src/pod.rs Outdated
impl PodTransmutable for u64 {}
impl PodTransmutable for i64 {}
impl PodTransmutable for char {}
#[cfg(stage0)]
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this cfg() argument right, btw?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, byteorder seems to be using #[cfg(feature = "i128")]. IMO we should do the same.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, cool. I stole this from libcore so I wasn't sure.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean, it has its own conditional feature for this (code). The real Rust compiler feature for these types is feature(i128_type).

Copy link
Owner Author

@nabijaczleweli nabijaczleweli Oct 10, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does that mean that #[cfg(i128_type)] is correct, or?
Turns out it is.

@Enet4
Copy link
Collaborator

Enet4 commented Oct 9, 2017

Oh by the way, don't close #5 yet because we should at least do something about the floaty ones.

@nabijaczleweli
Copy link
Owner Author

Fixed typo, feature gate and float impl.

@nabijaczleweli nabijaczleweli merged commit 9624e8d into master Oct 14, 2017
@nabijaczleweli nabijaczleweli deleted the pod branch October 14, 2017 13:08
@nabijaczleweli
Copy link
Owner Author

Released in v0.5.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants