define type for state data

This commit is contained in:
Edward Shen 2019-12-26 16:18:15 -05:00
parent 062c8f5a2e
commit 0a8af55f05
Signed by: edward
GPG key ID: F350507060ED6C90

View file

@ -12,6 +12,8 @@ use serde::Deserialize;
use std::collections::HashMap; use std::collections::HashMap;
use std::sync::{Arc, RwLock}; use std::sync::{Arc, RwLock};
type StateData = Data<Arc<RwLock<State>>>;
/// https://url.spec.whatwg.org/#fragment-percent-encode-set /// https://url.spec.whatwg.org/#fragment-percent-encode-set
const FRAGMENT_ENCODE_SET: &AsciiSet = &CONTROLS const FRAGMENT_ENCODE_SET: &AsciiSet = &CONTROLS
.add(b' ') .add(b' ')
@ -43,7 +45,7 @@ pub struct SearchQuery {
#[get("/hop")] #[get("/hop")]
pub async fn hop( pub async fn hop(
data: Data<Arc<RwLock<State>>>, data: StateData,
req: HttpRequest, req: HttpRequest,
query: Query<SearchQuery>, query: Query<SearchQuery>,
) -> impl Responder { ) -> impl Responder {
@ -121,10 +123,7 @@ fn resolve_hop(
} }
#[get("/")] #[get("/")]
pub async fn index( pub async fn index(data: StateData, req: HttpRequest) -> impl Responder {
data: Data<Arc<RwLock<State>>>,
req: HttpRequest,
) -> impl Responder {
let data = data.read().unwrap(); let data = data.read().unwrap();
HttpResponse::Ok().body( HttpResponse::Ok().body(
req req
@ -139,10 +138,7 @@ pub async fn index(
} }
#[get("/bunbunsearch.xml")] #[get("/bunbunsearch.xml")]
pub async fn opensearch( pub async fn opensearch(data: StateData, req: HttpRequest) -> impl Responder {
data: Data<Arc<RwLock<State>>>,
req: HttpRequest,
) -> impl Responder {
let data = data.read().unwrap(); let data = data.read().unwrap();
HttpResponse::Ok() HttpResponse::Ok()
.header( .header(