Add concat_panic_truncate function and macro, to allow panics with a configurable max upper bound#14
Open
dgarrett wants to merge 1 commit intorodrimati1992:mainfrom
Open
Conversation
…configurable max upper bound
Owner
|
My preference would be to implement overriding the maximum through either a set of cargo features (where it would pick the mimimum of all enabled features), or using environment variables (would require some parsing). The only reason to use the approach in this PR is if one needs to truncate to different lengths in different parts of the code. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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_panicin 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_LENitself configurable based on a cargo feature, maybesmall_stackto set some max like64or 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.