docs: more model documentation

This commit is contained in:
ThetaDev 2022-09-27 16:25:47 +02:00
parent 305c3ee70e
commit 49f3aa3577
7 changed files with 48 additions and 23 deletions

View file

@ -141,6 +141,9 @@ pub async fn generate_locales(project_root: &Path) {
let (languages, countries) = get_locales().await;
let code_head = r#"// This file is automatically generated. DO NOT EDIT.
//! Languages and countries
use std::{fmt::Display, str::FromStr};
use serde::{Deserialize, Serialize};
@ -177,28 +180,41 @@ impl FromStr for Country {
}
"#;
let mut code_langs =
r#"#[derive(Copy, Clone, Debug, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord, Hash)]
let mut code_langs = r#"/// Available languages
#[derive(Copy, Clone, Debug, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[serde(rename_all = "lowercase")]
pub enum Language {
"#.to_owned();
"#
.to_owned();
let mut code_countries =
r#"#[derive(Copy, Clone, Debug, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord, Hash)]
let mut code_countries = r#"/// Available countries
#[derive(Copy, Clone, Debug, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[serde(rename_all = "UPPERCASE")]
pub enum Country {
"#.to_owned();
"#
.to_owned();
let mut code_lang_array = format!("pub const LANGUAGES: [Language; {}] = [\n", languages.len());
let mut code_country_array =
format!("pub const COUNTRIES: [Country; {}] = [\n", countries.len());
let mut code_lang_array = format!(
"/// Array of all available languages\npub const LANGUAGES: [Language; {}] = [\n",
languages.len()
);
let mut code_country_array = format!(
"/// Array of all available countries\npub const COUNTRIES: [Country; {}] = [\n",
countries.len()
);
let mut code_lang_names = r#"impl Language {
/// Get the native name of the language
///
/// Examples: "English (US)", "Deutsch", "中文 (简体)"
pub fn name(&self) -> &str {
match self {
"#
.to_owned();
let mut code_country_names = r#"impl Country {
/// Get the English name of the country
///
/// Examples: "United States", "Germany"
pub fn name(&self) -> &str {
match self {
"#