Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Add From and TryFrom impls in libc_enum macro #1088
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
Add From and TryFrom impls in libc_enum macro #1088
Changes from all commits
a0dd24c
aedd467
367a4d6
1a14711
14de743
f9b344d
84a6620
c225ee6
e4b4e91
fa5641f
b2dcb49
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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.
Doc strings and cfg attributes are both different kinds of attributes. Could you simplify the macro by combining these two lines?
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.
The compiler emits a warning for "unused doc comment" when it sees a doc comment annotating a match arm, so I match them separately here so that I can use the
cfg
attributes on their own later.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.
why cast to
isize
? It seems like$prim
would be more appropriate.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.
isize
is the type that rust expects here. I tried using$prim
, but that requires adding a#[repr($prim)]
attribute to the enum, which I couldn't get to work for some reason I unfortunately can't remember.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.
Given the way that these types will be used, I think that
#[repr($prim)]
would be better. Could you try again to make it work? Show me the error if you have trouble.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.
The problem is that in some places we're using a custom type as
$prim
, and it turns out therepr
attribute only works with simple unsigned or signed integer typesu*
andi*
(see the Rustonomicon).The reason we need to use a custom type is that in some cases the underlying type depends on the target machine. I'm not sure how we could get around that with the
enum Signal : c_int
syntax I set up here.Can you share an example where the repr makes a difference?
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.
I think that's a fine choice of error.
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.
The reason I doubt is that
Error::Sys(Errno::EINVAL)
probably makes one think this is a "system error" that was picked up fromerrno
.How about adding an
Error::InvalidConversion
?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.
Yeah, I understand.
Error::InvalidConversion
would work, too.