'How can I get enum value by its name? [duplicate]

I know how to do it in Java.

It seems I need to implement TryFrom or something like that.

enum ROMAN {
    I = 1,
    V = 5,
    X = 10,
    L = 50,
    C = 100,
    D = 500,
    M = 1000
}

I want to get value using by enums name.

println!("{:?}", ROMAN::valueOf("M")); // It should be `1000`


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source