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

Use Box<[Type]> inside of FunctionType` #2036

Merged
merged 1 commit into from
Jan 22, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions lib/wasmer-types/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,9 +229,9 @@ impl ExternType {
#[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))]
pub struct FunctionType {
/// The parameters of the function
params: Vec<Type>,
params: Box<[Type]>,
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this affect serde somehow?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't believe it should, but that's a good thing to check -- thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Alright, checked the serde source code: they're both serialized as sequences, so there shouldn't be any effect on the serialization in any format

/// The return values of the function
results: Vec<Type>,
results: Box<[Type]>,
}

impl FunctionType {
Expand All @@ -242,8 +242,8 @@ impl FunctionType {
Returns: Into<Vec<Type>>,
{
Self {
params: params.into(),
results: returns.into(),
params: params.into().into_boxed_slice(),
results: returns.into().into_boxed_slice(),
Copy link
Contributor

Choose a reason for hiding this comment

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

Rust can infer the target type of returns.into() to the temporary Vec<Type>? Impressive.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In this case, params and returns and generic and the only thing we know about these types is that they implement Into<Vec<Type>>, but I agree that it is nice!

}
}

Expand Down