Skip to content

Provide a newtype wrapper? #24

Open
@RReverser

Description

@RReverser

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.

Activity

RReverser

RReverser commented on Mar 24, 2020

@RReverser
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

nagisa commented on Mar 24, 2020

@nagisa
Member

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

RReverser commented on Mar 25, 2020

@RReverser
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

nagisa commented on Mar 26, 2020

@nagisa
Member

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

RReverser commented on Mar 26, 2020

@RReverser
Author

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

nagisa

nagisa commented on Nov 14, 2021

@nagisa
Member

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @RReverser@nagisa

        Issue actions

          Provide a newtype wrapper? · Issue #24 · rust-lang/stacker