Skip to content

Add type_info-based example - #9

Open
bushrat011899 wants to merge 1 commit into
rustfoundation:mainfrom
bushrat011899:tuple_reflection
Open

Add type_info-based example#9
bushrat011899 wants to merge 1 commit into
rustfoundation:mainfrom
bushrat011899:tuple_reflection

Conversation

@bushrat011899

Copy link
Copy Markdown

Demonstrates getting information about the splatted tuple through type_info (compile-time reflection), which allows working with arbitrarily large tuples under certain circumstances.

@teor2345 teor2345 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Just some very minor nitpicks, none of these are blocking, but it would be nice to tweak them

#![feature(const_trait_impl)]
#![feature(splat)]
#![feature(tuple_trait)]
#![feature(type_info)]

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Christmas tree unstable features 😂
https://en.wikipedia.org/wiki/Christmas_tree_packet

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

It took a lot to resist adding const generic expressions too...

dbg!(min(1, 2, 3, 4));
// our type_info based alternative is able to accept an arbitrary number of
// arguments, but practically compilation times will become prohibitively long
// around 15,000 arguments.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Of course you tested this, nice.

The argument limit for Rust functions is u16::MAX. The position of splat is temporarily limited to u8::MAX for performance, but it can expand to any number of arguments, or have any number of non-splatted arguments after it.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Yeah I figured if I'm gonna say it supports an arbitrarily large number of arguments, I should actually check it does.

Comment thread Cargo.toml Outdated
resolver = "3"
members = [
"cpp-hypot-overload",
"cpp-hypot-overload", "tuple-reflection",

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Style nit: I think we are doing each item on a separate line in this file

Suggested change
"cpp-hypot-overload", "tuple-reflection",
"cpp-hypot-overload",
"tuple-reflection",

Comment thread tuple-reflection/Cargo.toml Outdated
[package]
name = "tuple-reflection"
version.workspace = true
authors.workspace = true

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Please add yourself as (the only) author 🙂

homepage.workspace = true
keywords.workspace = true
license.workspace = true
readme.workspace = true

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Please add the command to run/test this crate to the README.

Optional: free free to add more description in a new section as well, if you want.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I decided to just tack it below the other command rather than add a new section. I feel like if you added more examples it might be worth making a section per though.

Demonstrates getting information about the splatted tuple through `type_info` (compile-time reflection), which allows working with arbitrarily large tuples under certain circumstances.
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