35 lines
743 B
Rust
35 lines
743 B
Rust
use std::str::FromStr;
|
|
|
|
use crate::domain;
|
|
|
|
use super::types::QueryParams;
|
|
|
|
#[derive(Debug, Default, Clone)]
|
|
pub struct Context {
|
|
lang: Option<String>,
|
|
}
|
|
|
|
impl<'a> From<&QueryParams<'a>> for Context {
|
|
fn from(params: &QueryParams<'a>) -> Self {
|
|
params.iter().fold(Context::default(), |mut opts, p| {
|
|
match p {
|
|
("lang", val) => opts.lang = Some(String::from(*val)),
|
|
_ => {}
|
|
};
|
|
|
|
opts
|
|
})
|
|
}
|
|
}
|
|
|
|
impl From<Context> for domain::Context {
|
|
fn from(rest: Context) -> Self {
|
|
Self {
|
|
lang: rest
|
|
.lang
|
|
.and_then(|l| domain::Lang::from_str(&l).ok())
|
|
.unwrap_or_default(),
|
|
}
|
|
}
|
|
}
|