Questions tagged [associated-const]
4 questions
5
votes
1 answer
Associated constants in condition of constant ìf`-expression
I am trying to use associated constants as a condition in an if-expression to initialize another constant. I think that this should work, as I can use the associated constants directly to initialize some other constant, so it is applicable in a…

Jens
- 9,058
- 2
- 26
- 43
3
votes
2 answers
Why can't a type alias use associated constants from the original type in Rust?
Editor's note: As of Rust 1.43, this works as expected.
I have a type alias type CardId = u64; and I want to initialize it to the maximum number it can have through the std::u64::MAX constant. And was surprised to learn that I cannot do the same…

FireFlyForLife
- 93
- 1
- 7
2
votes
1 answer
Mismatched types when using associated consts and const generics in Rust nightly
So for a library I am writing, I want to calculate the distance between two points in N dimensions (2, 3, 4, etc...) and I have a Point trait so that user's of the library can use this function on their own types, so long as they are "point like".
I…

scott97
- 75
- 5
0
votes
1 answer
Assosiated function that returns an element of an assosiated const array?
I illustrate this general question with an example: I have a Color-Struct which holds three u8s (Red, Green, Blue). Color has an assosiated constant Color::PREDEFINED with some predefined colors. I need an assosiated function Color::pick_one…

ferdi2003
- 23
- 5