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

Add support for NonZero<T> #964

Closed
wants to merge 1 commit into from

Conversation

scovich
Copy link
Contributor

@scovich scovich commented May 22, 2024

Currently, cbindgen only supports the various NonZeroXX type aliases, but not NonZero<T> itself. Add that support, and also simplify the handling of types in general.

"c_short" => (IntKind::Short, true),
"c_int" => (IntKind::Int, true),
"c_long" => (IntKind::Long, true),
"c_longlong" => (IntKind::LongLong, true),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This PR is best reviewed with whitespace changes hidden:
image

@@ -592,50 +516,14 @@ impl Type {
}
}

fn nonzero_to_primitive(&self) -> Option<Self> {
Copy link
Contributor Author

@scovich scovich May 22, 2024

Choose a reason for hiding this comment

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

NOTE: This function is no longer needed, because the parser handles these types directly now.

Comment on lines +109 to +111
// NOTE: This performs the type erasure directly, as if `NonZero<T>` had been specified, because
// it's actually more code to register an erased typedef instead.
fn maybe_nonzero_integer(path: &str) -> Option<PrimitiveType> {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

NOTE: This replaces Type::nonzero_to_primitive

Copy link
Collaborator

@emilio emilio left a comment

Choose a reason for hiding this comment

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

Sweet.

fn simplified_type(&self, config: &Config) -> Option<Self> {
let path = match *self {
Type::Path(ref p) => p,
_ => return None,
};

if path.generics().is_empty() {
return self.nonzero_to_primitive();
return Some(self.clone());
Copy link
Collaborator

Choose a reason for hiding this comment

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

You can just return None, which is the shorthand for "no simplification needed", right?

@emilio emilio closed this in ad84541 May 26, 2024
@emilio
Copy link
Collaborator

emilio commented May 26, 2024

Merged with that tweak.

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.

2 participants