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

Extract into const #14886

Closed
yoav-lavi opened this issue May 25, 2023 · 2 comments
Closed

Extract into const #14886

yoav-lavi opened this issue May 25, 2023 · 2 comments
Labels
C-feature Category: feature request

Comments

@yoav-lavi
Copy link

Hey, I think a useful action for &'static str would be "Extract into const":

let opt_env_var = std::env::var("SOME_ENV_VAR").ok();

➜ Extract into const

const SOME_ENV_VAR: &str = "SOME_ENV_VAR";

let opt_env_var = std::env::var(SOME_ENV_VAR).ok();

Suggested behavior:

const {SCREAMING_SNAKE_CASE_STR_CONTENT}: &str = {str_content};

/* previous location ➜ */ {SCREAMING_SNAKE_CASE_STR_CONTENT}
  • The name could either be the &'static str content or a generic placeholder. The content is beneficial since it may reduce the amount of times the const needs to be renamed, but it's less likely to be correct for longer content.
  • Not 100% sure if it should be moved to the root scope or to the top of the current scope
  • Could be extended to all literals with different rules for naming

Thanks for your consideration!

@yoav-lavi yoav-lavi added the C-feature Category: feature request label May 25, 2023
@yoav-lavi
Copy link
Author

yoav-lavi commented May 25, 2023

Looks like this may be a duplicate of #7692, currently leaving this open since it has some extra suggestions for behavior but can be closed

@lnicola
Copy link
Member

lnicola commented Dec 13, 2024

Closing in favor of #18679.

@lnicola lnicola closed this as completed Dec 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-feature Category: feature request
Projects
None yet
Development

No branches or pull requests

2 participants