-
-
Notifications
You must be signed in to change notification settings - Fork 132
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
Formatter macros #2279
Comments
Thank you for this! It could be part of |
I think so too. |
why would this need to be a macro and not just a regular function (that would probably be inlined anyways by the compiler)? |
IMHO;
If there's any point where I'm mistaken, I would appreciate it if you could correct me. Thank you for reading. |
Would you be able to use a dynamic strings and also inline it with string literals with the same macro though? |
There are ways to achieve similar functionality using Rust macros by using token manipulation and code generation. You can generate code or tokens based on certain input, but this is not the same as creating truly dynamic strings within the macro. macro_rules! bold {
($content:expr) => {
format!("**{}**", $content)
};
} |
But yes, I agree that macros tend to be less general-purpose, and functions can often serve as more versatile and maintainable alternatives. Functions are typically more suitable for common tasks and can be used in a wider range of scenarios. However, macros still have their place in Rust for code generation, metaprogramming, and other compile-time tasks where their capabilities shine. I still believe that macros are useful and can be used effectively. |
just strapping an #[inline] on the function will cause it to be inlined, thus making it functionally equivalent to the macro, but much more readable imo macro's are useful but i don't think they offer any benefit here over just a macro |
You will get zero performance benefits for using |
Yes, I agree. Thank you for sharing your perspective. So functions are the best approach to these requirements, right? |
What would you like implemented? What do you want that Twilight lacks?
I would like to see the addition of macros like
bold!
,heading!
,code_block!
, andspoiler!
in the Twilight library. These macros should allow developers to easily format text for Discord messages without the need for manual string manipulation. This feature would enhance the library's capabilities and improve the developer experience.Are you willing to help towards contributing this feature?
Yes, I am enthusiastic about contributing to the implementation of these macros. I am willing to assist with code contributions, documentation updates, and any other tasks necessary to bring this feature to fruition.
Is there any other information that we should know?
Reference Documentation:
You can find more information about Discord message formatting in the official Discord Developer Portal documentation. This reference will help users understand the standard formatting options used in Discord and how the proposed macros would align with these conventions.
Thank you for considering this feature request. I believe it will be a valuable addition to Twilight and greatly benefit the broader Discord bot development community.
The text was updated successfully, but these errors were encountered: