Skip to content

Stability of the enum-map impl #133

Closed Answered by greyblake
aumetra asked this question in Q&A
Discussion options

You must be logged in to vote

Hi,

you don't need enum-map for that. It would be misuse.

You can convert whatlang::Lang to an integer by simple casting:

use whatlang::Lang;

fn main() {
    let ukrainian_index = Lang::Ukr as i32;
    println!("ukranian_index = {ukrainian_index}");

    let esperanto_index = Lang::Epo as i32;
    println!("esperanto_index = {esperanto_index}");
}

Output:

ukranian_index = 10
esperanto_index = 0

This works, but I cannot give you guarantee, that this won't change in the next minor version (e.g. 0.17.0). The indices my rearrange a bit if we add a new language.

So I would strongly recommend NOT rely on this behavior if you want to persist languages in database.

If you need to persist langua…

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@aumetra
Comment options

@greyblake
Comment options

@aumetra
Comment options

Answer selected by aumetra
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants