-
|
I would like to use What are the stability guarantees around the |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
|
Hi, you don't need You can convert 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: 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 language in DB I'd recommend using ISO 639-3 codes. In DB you can use enums (e.g. if you're using Postgres). or just VARCHAR, string. Whatlang provides functions to convert language to code and back: use whatlang::Lang;
fn main() {
let code = Lang::Ukr.code();
println!("code = {code}");
let lang = Lang::from_code("epo").unwrap();
println!("lang = {}", lang.name());
}Output: |
Beta Was this translation helpful? Give feedback.
Hi,
you don't need
enum-mapfor that. It would be misuse.You can convert
whatlang::Langto an integer by simple casting:Output:
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…