Const fn std::ops::Add


is there a way to make std::ops::Add and Co. a const fn?

Using traits in a const context is already mostly implemented on nightly. You might want to read through the tracking issue to find out how it works and where it is along the path to stabilization:

1 Like

Note that the trait cannot be made const in all situations. For example, the only non-const operation in this expression is the plus:

const MY_STRING: String = String::new() + "hello world";

However, allocations are not possible in const contexts.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.