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

Add concat_panic_truncate function and macro, to allow panics with a configurable max upper bound #14

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

dgarrett
Copy link
Contributor

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, maybe small_stack to set some max like 64 or a series of max_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.

@rodrimati1992
Copy link
Owner

rodrimati1992 commented Oct 30, 2024

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.

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

Successfully merging this pull request may close these issues.

2 participants