Spaces:
Running
Running
File size: 2,090 Bytes
493c56b 765dcbd fa57233 493c56b 7d762b3 493c56b 765dcbd 493c56b 8c239e2 493c56b fa57233 765dcbd fa57233 493c56b 765dcbd fa57233 493c56b 765dcbd fa57233 493c56b 765dcbd d2e4822 fa57233 493c56b 7d762b3 765dcbd 7d762b3 765dcbd 7d762b3 765dcbd 7d762b3 fa57233 7d762b3 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
//! This module provides the models to parse cookies and search parameters from the search
//! engine website.
use std::borrow::Cow;
use serde::{Deserialize, Serialize};
use super::parser_models::Style;
/// A named struct which deserializes all the user provided search parameters and stores them.
#[derive(Deserialize)]
pub struct SearchParams {
/// It stores the search parameter option `q` (or query in simple words)
/// of the search url.
pub q: Option<Cow<'static, str>>,
/// It stores the search parameter `page` (or pageno in simple words)
/// of the search url.
pub page: Option<u32>,
/// It stores the search parameter `safesearch` (or safe search level in simple words) of the
/// search url.
pub safesearch: Option<u8>,
}
/// A named struct which is used to deserialize the cookies fetched from the client side.
#[allow(dead_code)]
#[derive(Deserialize, Serialize)]
pub struct Cookie<'a> {
#[serde(borrow)]
/// It stores the theme name used in the website.
pub theme: Cow<'a, str>,
#[serde(borrow)]
/// It stores the colorscheme name used for the website theme.
pub colorscheme: Cow<'a, str>,
#[serde(borrow)]
/// It stores the user selected upstream search engines selected from the UI.
pub engines: Cow<'a, [Cow<'a, str>]>,
/// It stores the user selected safe search level from the UI.
pub safe_search_level: u8,
#[serde(borrow)]
/// It stores the animation name used for the website theme.
pub animation: Option<Cow<'a, str>>,
}
impl<'a> Cookie<'a> {
/// server_models::Cookie contructor function
pub fn build(style: &'a Style, mut engines: Vec<Cow<'a, str>>, safe_search_level: u8) -> Self {
engines.sort();
Self {
theme: Cow::Borrowed(&style.theme),
colorscheme: Cow::Borrowed(&style.colorscheme),
engines: Cow::Owned(engines),
safe_search_level,
animation: style
.animation
.as_ref()
.map(|str| Cow::Borrowed(str.as_str())),
}
}
}
|