Add concat_panic_truncate function and macro, to allow panics with a configurable max upper bound #14
+46
−6
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I'm looking to use
const_panic
in an embedded system with little RAM. It's mostly used from const contexts, but it would be useful to be able to configure smaller max stack usage for potential run-time scenarios too.This change would allow a caller to configure a max panic message length for a particular panic. Because Rust doesn't allow math on a generic constant, it doesn't have the logic of starting with a smaller buffer and progressively growing up to the max.
An alternative to this approach might be to make
MAX_PANIC_MSG_LEN
itself configurable based on a cargo feature, maybesmall_stack
to set some max like64
or a series ofmax_panic_msg_len_32
/max_panic_msg_len_64
/max_panic_msg_len_128
/etc features, though mutually exclusive features are generally discouraged by Cargo.Do you have any thoughts on how you'd prefer this to be done? I'd be glad to take another pass at a solution if you prefer something like the cargo feature, or something else.