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

Compile-time constant evaluation? #176

Closed
pickfire opened this issue Mar 1, 2020 · 5 comments · Fixed by #192
Closed

Compile-time constant evaluation? #176

pickfire opened this issue Mar 1, 2020 · 5 comments · Fixed by #192

Comments

@pickfire
Copy link

pickfire commented Mar 1, 2020

Evaluate at compile-time, zero-cost and no runtime cost at the cost of longer compile time. Of course, lazy-static and similar crates would be an option.

https://github.com/rust-lang/rfcs/blob/master/text/0246-const-vs-static.md

@mgeisler
Copy link
Owner

mgeisler commented Mar 3, 2020

Hi @pickfire That's an interesting idea — if it's relatively easy to implement with the existing functions?

I always assumed that the cost of wrapping strings would be very low. Also, I expect most programs will spend more time waiting for I/O to complete than waiting for strings to be wrapped.

Do you have a different use case?

@pickfire
Copy link
Author

pickfire commented Mar 3, 2020

@mgeisler Yes, it it supposed to be very low. But then is it useful to have it it runtime when we could do it during compile time? Of course some parts still won't be able to use this feature when it involves String or ?Sized, but no reason we should not do it for &'static str which does not change. The best thing I see is, why not do it just because we can! :D

@mgeisler
Copy link
Owner

Thanks to @althonos, this is now possible. Please see his textwrap-macros crate: https://github.com/althonos/textwrap-macros. It let's you indent, dedent, and wrap strings — all at compile time.

@pickfire
Copy link
Author

pickfire commented Jun 27, 2020

Nice, but should we mention it in README and the first page in rustdoc to make it more discoverable? Or maybe pull it into this crate behind a feature flag?

@mgeisler
Copy link
Owner

Yeah, mentioning it in the documentation is a great idea!

I don't think textwrap should have a dependency on textwrap-macros — since textwrap-macros already has a dependency back to textwrap. It seems simpler to me to have the layering work like this:

textwrap-macros
    |
    v
textwrap-macros-impl
    |
    v
textwrap

Then there is no doubt as to what version is in play at any point.

@mgeisler mgeisler reopened this Jun 27, 2020
mgeisler added a commit that referenced this issue Jun 27, 2020
The crate makes it possible to use textwrap at compile time.

Fixes #176
mgeisler added a commit that referenced this issue Jun 27, 2020
The crate makes it possible to use textwrap at compile time.

Fixes #176
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 a pull request may close this issue.

2 participants