-
Notifications
You must be signed in to change notification settings - Fork 39
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
Can basic SmartString functions be made constant? #21
Comments
The constructor as is can't be made const because it relies on |
Oh, wait, no, this is actually blocking on const fns being unable to accept trait bounds on type variables. rust-lang/rust#57563 I'll leave this issue open to track progress on the above and implement it when it stabilises. |
Well, technically speaking you don't need to stop at trait bounds. You can do implementations for bound types: impl SmartString<Compact> {
pub const fn new() -> Self {
...
}
} Which means implementing the same functions for all trait combinations. |
The problem is that |
That would be useful because we can then potentially put empty |
Ugh, well, I can remove the type parameter on On the other hand, it might be useful to expose |
That true. That's what I figured. How about a macro? Since all those implementations would not depend on the actual generic parameter and the code would all be the same. |
There are a lot of trait impls which rely on |
It is not critical... right now it only affects making constants, which is not really a big deal, so I would say don't do it if it is too much of a mess. I personally would keep And I'm not sure if it is impossible to make |
OK, after some experimentation, I can make a const empty constructor but I can't make a const constructor from a string slice (pending const I'm thinking I'll add the |
I suppose without a const constructor from a string slice, it won't be very useful to have const |
Kudos! Removing |
For example,
new
,is_empty
,len
etc. can probably be made constant, which can be helpful for defining other constant functions that use SmartString.I understand that SmartString is generic, so there would need to be separate constant implementations (all of them probably look exactly the same) for each function for each of the generic types.
The text was updated successfully, but these errors were encountered: