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

Provide a newtype wrapper? #24

Open
RReverser opened this issue Mar 24, 2020 · 6 comments
Open

Provide a newtype wrapper? #24

RReverser opened this issue Mar 24, 2020 · 6 comments

Comments

@RReverser
Copy link

The most common case for deep recursion is when handling deeply nested recursive types, where SomeType has a Box<SomeType> (or some other container) internally that can be nested really deeply, and then any standard operations that need to walk entire type, fail.

Suggestion: would it be worth providing a Stacker<T> newtype that automatically handles Deref, DerefMut, PartialEq, PartialOrd, Hash, Debug and so on and all other standard traits, but automatically checks and grows the stack before recursing?

It seems that such type would magically handle most common cases without user having to write any stack-growing code.

@RReverser
Copy link
Author

If you think this is useful, but doesn't belong in this crate, that's also fine and I'm happy to implement and publish it as a separate crate, but thought it might be useful raising here first.

@nagisa
Copy link
Member

nagisa commented Mar 24, 2020

I think it would make a lot of sense inside this crate, even if it ends up being opinionated in terms of how things are implemented, as long as they are well documented.

@RReverser
Copy link
Author

Cool. I guess the only open question is how to choose default limits for maybe_grow... Is there any "safe" lowest boundary for red zone that we could use universally?

Alternatively, if the callback is marked as #[inline(never)], is the red zone more predictable than with potentially inlined callbacks?

@nagisa
Copy link
Member

nagisa commented Mar 26, 2020

There's probably not a good red zone that would apply universally. Perhaps it would make sense to supply some value as a defaulted const generic (when those come around?).

@RReverser
Copy link
Author

I guess, although might take long time to wait for it.

@nagisa
Copy link
Member

nagisa commented Nov 14, 2021

There's some support for const generics now, so this is back on the table, I guess.

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

No branches or pull requests

2 participants