As a library author, what should my `#![recursion_limit]` be?

This is related to this issue.


I am the author of sosecrets-rs and right now, I am writing RTSecret<T, MEC: typenum::Unsigned>, which represents a secret that would return an Err or panics only if the value of its internal counter (a counter that measures the number of time a secret is exposed, I name it as ec) exceeds the runtime unsigned integer value represented by the type parameter MEC.

In this issue, @2e71828 helped me to write a declarative macro, named, impl_choose_int!(...) which in a brute force manner, implements the trait like so:

trait ChooseInt {
    type Output;

to all type level unsigned integers representable by 1 to 64 bits.

I simply extended it to 128 bits, hoping to support architectures that may support 128 bits pointer width. Let's not argue if this extension is even necessary but let's go with this as a hard requirement.


As you can see in the above playground, I put a macro #![recursion_limit = "256"] right at the top to support the compiler's compile time recursion limit to be 256. Else, I would encounter this error:

error: recursion limit reached while expanding `impl_choose_int!`
   --> src/
44  | /         impl_choose_int!{
45  | |             @prev_args ($($prev_args,)* $arg,);
46  | |             @prev_num UInt<$prev_num, $arg>;
47  | |             @rest_args ($($rest_args,)*);
48  | |             @rest_out ($($rest_out;)*);
49  | |         }
    | |_________^
61  | / impl_choose_int! {
62  | |     B00 => u8;
63  | |     B01 => u8;
64  | |     B02 => u8;
...   |
204 | |     B157 => u128;
205 | | }
    | |_- in this macro invocation
    = help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`playground`)
    = note: this error originates in the macro `impl_choose_int` (in Nightly builds, run with -Z macro-backtrace for more info)

error: could not compile `playground` (bin "playground") due to 1 previous error

My question is, as a library author, in wanting to support the usage of 128 bits representation in my users' binaries, should I then allow this #![recursion_limit = "256"] macro declaration at the module level? How would this impact my downstream users?

So, you need the attribute in your own crate? It's a crate-level attribute, so that's fine. It shouldn't effect other crates' recursion limit.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.