From 002bb24b26fbdfa6a664a10a109d763ca2f3f989 Mon Sep 17 00:00:00 2001 From: Nikolay Kim Date: Fri, 7 Sep 2018 20:46:43 -0700 Subject: [PATCH] unhide SessionBackend and SessionImpl traits and cleanup warnings --- CHANGES.md | 6 ++++++ Cargo.toml | 1 + src/client/connector.rs | 1 + src/lib.rs | 1 + src/middleware/session.rs | 8 ++++++-- src/router.rs | 36 +++++++++++++++++++++++++----------- src/server/http.rs | 12 ++++++------ 7 files changed, 46 insertions(+), 19 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 3a5a68de4..e5de591f0 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -5,8 +5,14 @@ ### Fixed * Fix system_exit in HttpServer #501 + * Fix parsing of route param containin regexes with repetition #500 +### Changes + +* Unhide `SessionBackend` and `SessionImpl` traits #455 + + ## [0.7.5] - 2018-09-04 ### Added diff --git a/Cargo.toml b/Cargo.toml index 704eac47a..6855c0ead 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -101,6 +101,7 @@ tokio-io = "0.1" tokio-tcp = "0.1" tokio-timer = "0.2" tokio-reactor = "0.1" +tokio-current-thread = "0.1" # native-tls native-tls = { version="0.2", optional = true } diff --git a/src/client/connector.rs b/src/client/connector.rs index 239a00c5e..896f98a41 100644 --- a/src/client/connector.rs +++ b/src/client/connector.rs @@ -204,6 +204,7 @@ impl Paused { /// `ClientConnector` type is responsible for transport layer of a /// client connection. pub struct ClientConnector { + #[allow(dead_code)] connector: SslConnector, stats: ClientConnectorStats, diff --git a/src/lib.rs b/src/lib.rs index f57ab937e..2559f6460 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -118,6 +118,7 @@ extern crate parking_lot; extern crate rand; extern crate slab; extern crate tokio; +extern crate tokio_current_thread; extern crate tokio_io; extern crate tokio_reactor; extern crate tokio_tcp; diff --git a/src/middleware/session.rs b/src/middleware/session.rs index 7bf5c0e95..e8b0e5558 100644 --- a/src/middleware/session.rs +++ b/src/middleware/session.rs @@ -270,14 +270,17 @@ impl> Middleware for SessionStorage { } /// A simple key-value storage interface that is internally used by `Session`. -#[doc(hidden)] pub trait SessionImpl: 'static { + /// Get session value by key fn get(&self, key: &str) -> Option<&str>; + /// Set session value fn set(&mut self, key: &str, value: String); + /// Remove specific key from session fn remove(&mut self, key: &str); + /// Remove all values from session fn clear(&mut self); /// Write session to storage backend. @@ -285,9 +288,10 @@ pub trait SessionImpl: 'static { } /// Session's storage backend trait definition. -#[doc(hidden)] pub trait SessionBackend: Sized + 'static { + /// Session item type Session: SessionImpl; + /// Future that reads session type ReadFuture: Future; /// Parse the session from request and load data from a storage backend. diff --git a/src/router.rs b/src/router.rs index 4a0f672c5..ab84838f1 100644 --- a/src/router.rs +++ b/src/router.rs @@ -815,16 +815,21 @@ impl ResourceDef { Ok(()) } - fn parse_param( - pattern: &str, - ) -> (PatternElement, String, &str) { + fn parse_param(pattern: &str) -> (PatternElement, String, &str) { const DEFAULT_PATTERN: &str = "[^/]+"; let mut params_nesting = 0usize; - let close_idx = pattern.find(|c| match c { - '{' => {params_nesting += 1; false}, - '}' => {params_nesting -= 1; params_nesting == 0}, - _ => false - }).expect("malformed param"); + let close_idx = pattern + .find(|c| match c { + '{' => { + params_nesting += 1; + false + } + '}' => { + params_nesting -= 1; + params_nesting == 0 + } + _ => false, + }).expect("malformed param"); let (mut param, rem) = pattern.split_at(close_idx + 1); param = ¶m[1..param.len() - 1]; // Remove outer brackets let (name, pattern) = match param.find(":") { @@ -832,16 +837,25 @@ impl ResourceDef { let (name, pattern) = param.split_at(idx); (name, &pattern[1..]) } - None => (param, DEFAULT_PATTERN) + None => (param, DEFAULT_PATTERN), }; - (PatternElement::Var(name.to_string()), format!(r"(?P<{}>{})", &name, &pattern), rem) + ( + PatternElement::Var(name.to_string()), + format!(r"(?P<{}>{})", &name, &pattern), + rem, + ) } fn parse( mut pattern: &str, for_prefix: bool, ) -> (String, Vec, bool, usize) { if pattern.find("{").is_none() { - return (String::from(pattern), vec![PatternElement::Str(String::from(pattern))], false, pattern.chars().count()) + return ( + String::from(pattern), + vec![PatternElement::Str(String::from(pattern))], + false, + pattern.chars().count(), + ); }; let mut elems = Vec::new(); diff --git a/src/server/http.rs b/src/server/http.rs index ed463f75d..eafd45a3f 100644 --- a/src/server/http.rs +++ b/src/server/http.rs @@ -3,12 +3,12 @@ use std::rc::Rc; use std::sync::Arc; use std::{io, mem, net, time}; -use actix::{Actor, Addr, Arbiter, AsyncContext, Context, Handler, System}; +use actix::{Actor, Addr, AsyncContext, Context, Handler, System}; use futures::{Future, Stream}; use net2::{TcpBuilder, TcpStreamExt}; use num_cpus; -use tokio::executor::current_thread; +use tokio_current_thread::spawn; use tokio_io::{AsyncRead, AsyncWrite}; use tokio_tcp::TcpStream; @@ -585,7 +585,7 @@ where type Result = (); fn handle(&mut self, msg: Conn, _: &mut Context) -> Self::Result { - Arbiter::spawn(HttpChannel::new( + spawn(HttpChannel::new( Rc::clone(&self.settings), msg.io, msg.peer, @@ -693,7 +693,7 @@ where }; let _ = io.set_nodelay(true); - current_thread::spawn(HttpChannel::new(h, io, peer)); + spawn(HttpChannel::new(h, io, peer)); } } @@ -753,10 +753,10 @@ where let _ = io.set_nodelay(true); let rate = h.connection_rate(); - current_thread::spawn(self.acceptor.accept(io).then(move |res| { + spawn(self.acceptor.accept(io).then(move |res| { drop(rate); match res { - Ok(io) => current_thread::spawn(HttpChannel::new(h, io, peer)), + Ok(io) => spawn(HttpChannel::new(h, io, peer)), Err(err) => trace!("Can not establish connection: {}", err), } Ok(())