Added isolang as a message field.
This commit is contained in:
parent
ac0df7ae1f
commit
2c9b08c77d
34
Cargo.lock
generated
34
Cargo.lock
generated
@ -472,6 +472,15 @@ version = "1.70.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf"
|
||||
|
||||
[[package]]
|
||||
name = "isolang"
|
||||
version = "2.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fe50d48c77760c55188549098b9a7f6e37ae980c586a24693d6b01c3b2010c3c"
|
||||
dependencies = [
|
||||
"phf",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "itoa"
|
||||
version = "1.0.15"
|
||||
@ -556,6 +565,7 @@ dependencies = [
|
||||
"chrono",
|
||||
"clap",
|
||||
"http-body-util",
|
||||
"isolang",
|
||||
"serde_json",
|
||||
"tokio",
|
||||
"tower",
|
||||
@ -622,6 +632,24 @@ version = "2.3.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e"
|
||||
|
||||
[[package]]
|
||||
name = "phf"
|
||||
version = "0.11.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1fd6780a80ae0c52cc120a26a1a42c1ae51b247a253e4e06113d23d2c2edd078"
|
||||
dependencies = [
|
||||
"phf_shared",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "phf_shared"
|
||||
version = "0.11.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "67eabc2ef2a60eb7faa00097bd1ffdb5bd28e62bf39990626a582201b7a754e5"
|
||||
dependencies = [
|
||||
"siphasher",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "pin-project-lite"
|
||||
version = "0.2.16"
|
||||
@ -766,6 +794,12 @@ dependencies = [
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "siphasher"
|
||||
version = "1.0.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "56199f7ddabf13fe5074ce809e7d3f42b42ae711800501b5b16ea82ad029c39d"
|
||||
|
||||
[[package]]
|
||||
name = "slab"
|
||||
version = "0.4.9"
|
||||
|
||||
@ -9,6 +9,7 @@ edition = "2021"
|
||||
axum = ">=0.8.0"
|
||||
chrono = { version = ">=0.4.40", features = ["now"] }
|
||||
clap = { version = ">=4.5.1", features = ["derive"] }
|
||||
isolang = ">=2.4.0"
|
||||
serde_json = ">=1.0.140"
|
||||
tokio = { version = ">=1.36.0", features = ["full"] }
|
||||
tower-cookies = ">=0.11.0"
|
||||
|
||||
@ -11,6 +11,27 @@ use std::{
|
||||
|
||||
const RESPONDS_TO: [MsgType; 1] = [MsgType::DocumentRequest];
|
||||
|
||||
struct Table;
|
||||
|
||||
impl Table {
|
||||
fn new() -> Self {
|
||||
Self {}
|
||||
}
|
||||
|
||||
fn add_column(&self) {}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tables {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn create_table() {
|
||||
let tbl = Table::new();
|
||||
tbl.add_column();
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Document {
|
||||
data: HashMap<String, String>,
|
||||
queue: Queue,
|
||||
|
||||
53
src/field.rs
53
src/field.rs
@ -1,12 +1,13 @@
|
||||
use crate::{ActionType, ErrorType};
|
||||
use chrono::prelude::*;
|
||||
use isolang::Language;
|
||||
use std::fmt;
|
||||
use uuid::Uuid;
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
enum FieldType {
|
||||
Action,
|
||||
DateTime,
|
||||
DateTime,
|
||||
Error,
|
||||
StaticString,
|
||||
Uuid,
|
||||
@ -17,6 +18,7 @@ pub enum Field {
|
||||
Action(ActionType),
|
||||
DateTime(DateTime<Utc>),
|
||||
ErrorType(ErrorType),
|
||||
Lang(Language),
|
||||
Static(String),
|
||||
Uuid(Uuid),
|
||||
}
|
||||
@ -49,6 +51,13 @@ impl Field {
|
||||
_ => Err("not an error type".to_string()),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn to_language(&self) -> Result<Language, String> {
|
||||
match self {
|
||||
Field::Lang(data) => Ok(data.clone()),
|
||||
_ => Err("not an error type".to_string()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<String> for Field {
|
||||
@ -95,6 +104,12 @@ impl From<ErrorType> for Field {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Language> for Field {
|
||||
fn from(value: Language) -> Self {
|
||||
Field::Lang(value)
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for Field {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match self {
|
||||
@ -296,4 +311,40 @@ mod fields {
|
||||
Err(_) => {}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn from_lang_to_field() {
|
||||
let langs = [
|
||||
Language::from_639_1("en").unwrap(),
|
||||
Language::from_639_1("ja").unwrap(),
|
||||
];
|
||||
for lang in langs.into_iter() {
|
||||
let field: Field = lang.into();
|
||||
match field {
|
||||
Field::Lang(data) => assert_eq!(data, lang),
|
||||
_ => unreachable!("should identify language"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn from_field_to_lang() {
|
||||
let langs = [
|
||||
Language::from_639_1("en").unwrap(),
|
||||
Language::from_639_1("ja").unwrap(),
|
||||
];
|
||||
for lang in langs.into_iter() {
|
||||
let field: Field = lang.into();
|
||||
assert_eq!(field.to_language().unwrap(), lang);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn wrong_field_to_lang() {
|
||||
let field: Field = Uuid::nil().into();
|
||||
match field.to_language() {
|
||||
Ok(_) => unreachable!("should have produced an error"),
|
||||
Err(_) => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user