From 0e21b189bd7f23da402c6d96d42cf36cdc1b865b Mon Sep 17 00:00:00 2001 From: Daniel Sockwell Date: Fri, 17 Apr 2020 21:56:31 -0400 Subject: [PATCH] Adjust module privacy --- src/config.rs | 6 ++--- src/config/deployment_cfg.rs | 4 +-- src/config/environmental_variables.rs | 4 +-- src/config/postgres_cfg.rs | 6 ++--- src/config/redis_cfg.rs | 6 ++--- src/config/redis_cfg_types.rs | 2 +- src/err.rs | 36 ++++++++++++------------- src/lib.rs | 4 ++- src/main.rs | 30 ++++++++------------- src/request.rs | 15 ++++++----- src/request/err.rs | 39 ++++++++++++++++++++++----- src/request/postgres.rs | 2 +- src/request/timeline.rs | 10 +++---- src/request/timeline/err.rs | 27 ------------------- src/request/timeline/inner.rs | 10 +++---- src/response.rs | 2 +- src/response/redis.rs | 12 +++++---- src/response/redis/connection.rs | 11 ++++---- src/response/redis/connection/err.rs | 10 +++---- src/response/redis/manager.rs | 4 +-- src/response/redis/manager/err.rs | 21 ++++++++------- 21 files changed, 130 insertions(+), 131 deletions(-) diff --git a/src/config.rs b/src/config.rs index f7c3089..76edcad 100644 --- a/src/config.rs +++ b/src/config.rs @@ -4,7 +4,7 @@ pub(crate) use redis_cfg::Redis; use deployment_cfg::Deployment; use self::environmental_variables::EnvVar; -use super::err::FatalErr; +use super::err::Error; use hashbrown::HashMap; use std::env; @@ -16,13 +16,13 @@ mod postgres_cfg_types; mod redis_cfg; mod redis_cfg_types; -type Result = std::result::Result; +type Result = std::result::Result; pub fn merge_dotenv() -> Result<()> { let env_file = match env::var("ENV").ok().as_deref() { Some("production") => ".env.production", Some("development") | None => ".env", - Some(v) => Err(FatalErr::config("ENV", v, "`production` or `development`"))?, + Some(v) => Err(Error::config("ENV", v, "`production` or `development`"))?, }; let res = dotenv::from_filename(env_file); diff --git a/src/config/deployment_cfg.rs b/src/config/deployment_cfg.rs index 379691e..efee4a6 100644 --- a/src/config/deployment_cfg.rs +++ b/src/config/deployment_cfg.rs @@ -1,5 +1,5 @@ use super::{deployment_cfg_types::*, EnvVar}; -use crate::err::FatalErr; +use crate::err::Error; #[derive(Debug, Default)] pub struct Deployment<'a> { @@ -13,7 +13,7 @@ pub struct Deployment<'a> { } impl Deployment<'_> { - pub(crate) fn from_env(env: &EnvVar) -> Result { + pub(crate) fn from_env(env: &EnvVar) -> Result { let mut cfg = Self { env: Env::default().maybe_update(env.get("NODE_ENV"))?, log_level: LogLevel::default().maybe_update(env.get("RUST_LOG"))?, diff --git a/src/config/environmental_variables.rs b/src/config/environmental_variables.rs index a1e08cf..497fa98 100644 --- a/src/config/environmental_variables.rs +++ b/src/config/environmental_variables.rs @@ -109,11 +109,11 @@ macro_rules! from_env_var { pub(crate) fn maybe_update( self, var: Option<&String>, - ) -> Result { + ) -> Result { Ok(match var { Some(empty_string) if empty_string.is_empty() => Self::default(), Some(value) => Self(Self::inner_from_str(value).ok_or_else(|| { - crate::err::FatalErr::config($env_var, value, $allowed_values) + crate::err::Error::config($env_var, value, $allowed_values) })?), None => self, }) diff --git a/src/config/postgres_cfg.rs b/src/config/postgres_cfg.rs index 2e62ff2..d94fe21 100644 --- a/src/config/postgres_cfg.rs +++ b/src/config/postgres_cfg.rs @@ -1,10 +1,10 @@ use super::{postgres_cfg_types::*, EnvVar}; -use crate::err::FatalErr; +use crate::err::Error; use url::Url; use urlencoding; -type Result = std::result::Result; +type Result = std::result::Result; #[derive(Debug, Clone)] pub struct Postgres { @@ -27,7 +27,7 @@ impl EnvVar { "password" => self.maybe_add_env_var("DB_PASS", Some(v.to_string())), "host" => self.maybe_add_env_var("DB_HOST", Some(v.to_string())), "sslmode" => self.maybe_add_env_var("DB_SSLMODE", Some(v.to_string())), - _ => Err(FatalErr::config( + _ => Err(Error::config( "POSTGRES_URL", &k, "a URL with parameters `password`, `user`, `host`, and `sslmode` only", diff --git a/src/config/redis_cfg.rs b/src/config/redis_cfg.rs index 5f85362..fe79364 100644 --- a/src/config/redis_cfg.rs +++ b/src/config/redis_cfg.rs @@ -1,10 +1,10 @@ use super::redis_cfg_types::*; use super::EnvVar; -use crate::err::FatalErr; +use crate::err::Error; use url::Url; -type Result = std::result::Result; +type Result = std::result::Result; #[derive(Debug, Default)] pub struct Redis { @@ -33,7 +33,7 @@ impl EnvVar { match k.to_string().as_str() { "password" => self.maybe_add_env_var("REDIS_PASSWORD", Some(v.to_string())), "db" => self.maybe_add_env_var("REDIS_DB", Some(v.to_string())), - _ => Err(FatalErr::config( + _ => Err(Error::config( "REDIS_URL", &k, "a URL with parameters `password`, `db`, only", diff --git a/src/config/redis_cfg_types.rs b/src/config/redis_cfg_types.rs index 94e7d1e..6e07063 100644 --- a/src/config/redis_cfg_types.rs +++ b/src/config/redis_cfg_types.rs @@ -1,4 +1,4 @@ -use crate::from_env_var; +use crate::from_env_var; //macro use std::time::Duration; //use std::{fmt, net::IpAddr, os::unix::net::UnixListener, str::FromStr, time::Duration}; //use strum_macros::{EnumString, EnumVariantNames}; diff --git a/src/err.rs b/src/err.rs index 557a2bf..e756524 100644 --- a/src/err.rs +++ b/src/err.rs @@ -1,11 +1,11 @@ -use crate::request::RequestErr; -use crate::response::ManagerErr; +use crate::request; +use crate::response; use std::fmt; -pub enum FatalErr { - ReceiverErr(ManagerErr), +pub enum Error { + ReceiverErr(response::Error), Logger(log::SetLoggerError), - Postgres(RequestErr), + Postgres(request::Error), Unrecoverable, StdIo(std::io::Error), // config errs @@ -14,7 +14,7 @@ pub enum FatalErr { ConfigErr(String), } -impl FatalErr { +impl Error { pub fn log(msg: impl fmt::Display) { eprintln!("{}", msg); } @@ -27,16 +27,16 @@ impl FatalErr { } } -impl std::error::Error for FatalErr {} -impl fmt::Debug for FatalErr { +impl std::error::Error for Error {} +impl fmt::Debug for Error { fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { write!(f, "{}", self) } } -impl fmt::Display for FatalErr { +impl fmt::Display for Error { fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { - use FatalErr::*; + use Error::*; write!( f, "{}", @@ -54,33 +54,33 @@ impl fmt::Display for FatalErr { } } -impl From for FatalErr { - fn from(e: RequestErr) -> Self { +impl From for Error { + fn from(e: request::Error) -> Self { Self::Postgres(e) } } -impl From for FatalErr { - fn from(e: ManagerErr) -> Self { +impl From for Error { + fn from(e: response::Error) -> Self { Self::ReceiverErr(e) } } -impl From for FatalErr { +impl From for Error { fn from(e: urlencoding::FromUrlEncodingError) -> Self { Self::UrlEncoding(e) } } -impl From for FatalErr { +impl From for Error { fn from(e: url::ParseError) -> Self { Self::UrlParse(e) } } -impl From for FatalErr { +impl From for Error { fn from(e: std::io::Error) -> Self { Self::StdIo(e) } } -impl From for FatalErr { +impl From for Error { fn from(e: log::SetLoggerError) -> Self { Self::Logger(e) } diff --git a/src/lib.rs b/src/lib.rs index f0731ca..70a5f8f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -39,8 +39,10 @@ #![allow(clippy::try_err, clippy::match_bool)] //#![allow(clippy::large_enum_variant)] +pub use err::Error; + pub mod config; -pub mod err; +mod err; pub mod event; pub mod request; pub mod response; diff --git a/src/main.rs b/src/main.rs index f1f3e3c..8479523 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,9 +1,9 @@ use flodgatt::config; -use flodgatt::err::FatalErr; use flodgatt::event::Event; use flodgatt::request::{Handler, Subscription, Timeline}; -use flodgatt::response::redis; +use flodgatt::response::redis::Manager; use flodgatt::response::stream; +use flodgatt::Error; use futures::{future::lazy, stream::Stream as _}; use std::fs; @@ -16,7 +16,7 @@ use tokio::timer::Interval; use warp::ws::Ws2; use warp::Filter; -fn main() -> Result<(), FatalErr> { +fn main() -> Result<(), Error> { config::merge_dotenv()?; pretty_env_logger::try_init()?; let (postgres_cfg, redis_cfg, cfg) = config::from_env(dotenv::vars().collect())?; @@ -27,7 +27,7 @@ fn main() -> Result<(), FatalErr> { let (cmd_tx, cmd_rx) = mpsc::unbounded_channel(); let request = Handler::new(&postgres_cfg, *cfg.whitelist_mode)?; - let shared_manager = redis::Manager::try_from(&redis_cfg, event_tx, cmd_rx)?.into_arc(); + let shared_manager = Manager::try_from(&redis_cfg, event_tx, cmd_rx)?.into_arc(); // Server Sent Events let sse_manager = shared_manager.clone(); @@ -37,7 +37,7 @@ fn main() -> Result<(), FatalErr> { .and(warp::sse()) .map(move |subscription: Subscription, sse: warp::sse::Sse| { log::info!("Incoming SSE request for {:?}", subscription.timeline); - let mut manager = sse_manager.lock().unwrap_or_else(redis::Manager::recover); + let mut manager = sse_manager.lock().unwrap_or_else(Manager::recover); manager.subscribe(&subscription); stream::Sse::send_events(sse, sse_cmd_tx.clone(), subscription, sse_rx.clone()) @@ -51,7 +51,7 @@ fn main() -> Result<(), FatalErr> { .and(warp::ws::ws2()) .map(move |subscription: Subscription, ws: Ws2| { log::info!("Incoming websocket request for {:?}", subscription.timeline); - let mut manager = ws_manager.lock().unwrap_or_else(redis::Manager::recover); + let mut manager = ws_manager.lock().unwrap_or_else(Manager::recover); manager.subscribe(&subscription); let token = subscription.access_token.clone().unwrap_or_default(); // token sent for security let ws_stream = stream::Ws::new(cmd_tx.clone(), event_rx.clone(), subscription); @@ -78,22 +78,14 @@ fn main() -> Result<(), FatalErr> { .allow_methods(cfg.cors.allowed_methods) .allow_headers(cfg.cors.allowed_headers); - // use futures::future::Future; let streaming_server = move || { let manager = shared_manager.clone(); let stream = Interval::new(Instant::now(), poll_freq) - // .take(1200) .map_err(|e| log::error!("{}", e)) - .for_each( - move |_| { - let mut manager = manager.lock().unwrap_or_else(redis::Manager::recover); - manager.poll_broadcast().map_err(FatalErr::log) - }, // ).and_then(|_| { - // log::info!("shutting down!"); - // std::process::exit(0); - // futures::future::ok(()) - // } - ); + .for_each(move |_| { + let mut manager = manager.lock().unwrap_or_else(Manager::recover); + manager.poll_broadcast().map_err(Error::log) + }); warp::spawn(lazy(move || stream)); warp::serve(ws.or(sse).with(cors).or(status).recover(Handler::err)) @@ -109,5 +101,5 @@ fn main() -> Result<(), FatalErr> { let server_addr = SocketAddr::new(*cfg.address, *cfg.port); tokio::run(lazy(move || streaming_server().bind(server_addr))); } - Err(FatalErr::Unrecoverable) // on get here if there's an unrecoverable error in poll_broadcast. + Err(Error::Unrecoverable) // only get here if there's an unrecoverable error in poll_broadcast. } diff --git a/src/request.rs b/src/request.rs index e265d77..7a2fc12 100644 --- a/src/request.rs +++ b/src/request.rs @@ -1,21 +1,22 @@ //! Parse the client request and return a Subscription mod postgres; mod query; -pub mod timeline; +mod timeline; -mod err; +pub mod err; mod subscription; -pub(crate) use self::err::RequestErr; pub(crate) use self::postgres::PgPool; +pub(crate) use err::Error; pub(crate) use subscription::Blocks; pub use subscription::Subscription; +pub(crate) use timeline::Stream; pub use timeline::Timeline; -pub(crate) use timeline::{Content, Reach, Stream, TimelineErr}; +use timeline::{Content, Reach}; use self::query::Query; -use crate::config; +use crate::config::Postgres; use warp::filters::BoxedFilter; use warp::http::StatusCode; use warp::path; @@ -26,7 +27,7 @@ mod sse_test; #[cfg(test)] mod ws_test; -type Result = std::result::Result; +type Result = std::result::Result; /// Helper macro to match on the first of any of the provided filters macro_rules! any_of { @@ -62,7 +63,7 @@ pub struct Handler { } impl Handler { - pub fn new(postgres_cfg: &config::Postgres, whitelist_mode: bool) -> Result { + pub fn new(postgres_cfg: &Postgres, whitelist_mode: bool) -> Result { Ok(Self { pg_conn: PgPool::new(postgres_cfg, whitelist_mode)?, }) diff --git a/src/request/err.rs b/src/request/err.rs index 0637e30..9050af9 100644 --- a/src/request/err.rs +++ b/src/request/err.rs @@ -1,15 +1,15 @@ use std::fmt; #[derive(Debug)] -pub enum RequestErr { +pub enum Error { PgPool(r2d2::Error), Pg(postgres::Error), } -impl std::error::Error for RequestErr {} +impl std::error::Error for Error {} -impl fmt::Display for RequestErr { +impl fmt::Display for Error { fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { - use RequestErr::*; + use Error::*; let msg = match self { PgPool(e) => format!("{}", e), Pg(e) => format!("{}", e), @@ -18,13 +18,40 @@ impl fmt::Display for RequestErr { } } -impl From for RequestErr { +impl From for Error { fn from(e: r2d2::Error) -> Self { Self::PgPool(e) } } -impl From for RequestErr { +impl From for Error { fn from(e: postgres::Error) -> Self { Self::Pg(e) } } +// TODO make Timeline & TimelineErr their own top-level module +#[derive(Debug)] +pub enum Timeline { + MissingHashtag, + InvalidInput, + BadTag, +} + +impl std::error::Error for Timeline {} + +impl From for Timeline { + fn from(_error: std::num::ParseIntError) -> Self { + Self::InvalidInput + } +} + +impl fmt::Display for Timeline { + fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { + use Timeline::*; + let msg = match self { + InvalidInput => "The timeline text from Redis could not be parsed into a supported timeline. TODO: add incoming timeline text", + MissingHashtag => "Attempted to send a hashtag timeline without supplying a tag name", + BadTag => "No hashtag exists with the specified hashtag ID" + }; + write!(f, "{}", msg) + } +} diff --git a/src/request/postgres.rs b/src/request/postgres.rs index a5ea50c..18cd970 100644 --- a/src/request/postgres.rs +++ b/src/request/postgres.rs @@ -15,7 +15,7 @@ pub struct PgPool { whitelist_mode: bool, } -type Result = std::result::Result; +type Result = std::result::Result; type Rejectable = std::result::Result; impl PgPool { diff --git a/src/request/timeline.rs b/src/request/timeline.rs index b8d221a..a521d05 100644 --- a/src/request/timeline.rs +++ b/src/request/timeline.rs @@ -1,5 +1,5 @@ -pub(crate) use self::err::TimelineErr; pub(crate) use self::inner::{Content, Reach, Scope, Stream, UserData}; +use super::err::Timeline as Error; use super::query::Query; use lru::LruCache; @@ -8,7 +8,7 @@ use warp::reject::Rejection; mod err; mod inner; -type Result = std::result::Result; +type Result = std::result::Result; #[derive(Clone, Debug, Copy, Eq, Hash, PartialEq)] pub struct Timeline(pub(crate) Stream, pub(crate) Reach, pub(crate) Content); @@ -20,7 +20,7 @@ impl Timeline { pub(crate) fn to_redis_raw_timeline(&self, hashtag: Option<&String>) -> Result { // TODO -- does this need to account for namespaces? - use {Content::*, Reach::*, Stream::*, TimelineErr::*}; + use {Content::*, Error::*, Reach::*, Stream::*}; Ok(match self { Timeline(Public, Federated, All) => "timeline:public".to_string(), @@ -42,7 +42,7 @@ impl Timeline { } Timeline(List(id), Federated, All) => ["timeline:list:", &id.to_string()].concat(), Timeline(Direct(id), Federated, All) => ["timeline:direct:", &id.to_string()].concat(), - Timeline(_one, _two, _three) => Err(TimelineErr::InvalidInput)?, + Timeline(_one, _two, _three) => Err(Error::InvalidInput)?, }) } @@ -50,7 +50,7 @@ impl Timeline { timeline: &str, cache: &mut LruCache, ) -> Result { - use {Content::*, Reach::*, Stream::*, TimelineErr::*}; + use {Content::*, Error::*, Reach::*, Stream::*}; let mut tag_id = |t: &str| cache.get(&t.to_string()).map_or(Err(BadTag), |id| Ok(*id)); Ok(match &timeline.split(':').collect::>()[..] { diff --git a/src/request/timeline/err.rs b/src/request/timeline/err.rs index 5dbf660..8b13789 100644 --- a/src/request/timeline/err.rs +++ b/src/request/timeline/err.rs @@ -1,28 +1 @@ -use std::fmt; -#[derive(Debug)] -pub enum TimelineErr { - MissingHashtag, - InvalidInput, - BadTag, -} - -impl std::error::Error for TimelineErr {} - -impl From for TimelineErr { - fn from(_error: std::num::ParseIntError) -> Self { - Self::InvalidInput - } -} - -impl fmt::Display for TimelineErr { - fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { - use TimelineErr::*; - let msg = match self { - InvalidInput => "The timeline text from Redis could not be parsed into a supported timeline. TODO: add incoming timeline text", - MissingHashtag => "Attempted to send a hashtag timeline without supplying a tag name", - BadTag => "No hashtag exists with the specified hashtag ID" - }; - write!(f, "{}", msg) - } -} diff --git a/src/request/timeline/inner.rs b/src/request/timeline/inner.rs index fd3a884..8bdf141 100644 --- a/src/request/timeline/inner.rs +++ b/src/request/timeline/inner.rs @@ -1,4 +1,4 @@ -use super::TimelineErr; +use super::Error; use crate::event::Id; use hashbrown::HashSet; @@ -36,18 +36,18 @@ pub(crate) enum Scope { } impl TryFrom<&str> for Scope { - type Error = TimelineErr; + type Error = Error; - fn try_from(s: &str) -> Result { + fn try_from(s: &str) -> Result { match s { "read" => Ok(Scope::Read), "read:statuses" => Ok(Scope::Statuses), "read:notifications" => Ok(Scope::Notifications), "read:lists" => Ok(Scope::Lists), - "write" | "follow" => Err(TimelineErr::InvalidInput), // ignore write scopes + "write" | "follow" => Err(Error::InvalidInput), // ignore write scopes unexpected => { log::warn!("Ignoring unknown scope `{}`", unexpected); - Err(TimelineErr::InvalidInput) + Err(Error::InvalidInput) } } } diff --git a/src/response.rs b/src/response.rs index b247dfd..4ce8d1f 100644 --- a/src/response.rs +++ b/src/response.rs @@ -3,7 +3,7 @@ pub mod redis; pub mod stream; -pub(crate) use redis::ManagerErr; +pub(crate) use redis::Error; #[cfg(feature = "bench")] pub use redis::msg::{RedisMsg, RedisParseOutput}; diff --git a/src/response/redis.rs b/src/response/redis.rs index da37491..0d69504 100644 --- a/src/response/redis.rs +++ b/src/response/redis.rs @@ -2,18 +2,20 @@ mod connection; mod manager; mod msg; -pub(crate) use connection::{RedisConn, RedisConnErr}; +pub(self) use connection::RedisConn; +pub(crate) use manager::Error; pub use manager::Manager; -pub(crate) use manager::ManagerErr; -pub(crate) use msg::RedisParseErr; -pub(crate) enum RedisCmd { +use connection::RedisConnErr; +use msg::RedisParseErr; + +enum RedisCmd { Subscribe, Unsubscribe, } impl RedisCmd { - pub(crate) fn into_sendable(self, tl: &str) -> (Vec, Vec) { + fn into_sendable(self, tl: &str) -> (Vec, Vec) { match self { RedisCmd::Subscribe => ( [ diff --git a/src/response/redis/connection.rs b/src/response/redis/connection.rs index ec0795c..7dd05ba 100644 --- a/src/response/redis/connection.rs +++ b/src/response/redis/connection.rs @@ -2,7 +2,8 @@ mod err; pub(crate) use err::RedisConnErr; use super::msg::{RedisParseErr, RedisParseOutput}; -use super::{ManagerErr, RedisCmd}; +use super::Error as ManagerErr; +use super::RedisCmd; use crate::config::Redis; use crate::event::Event; use crate::request::{Stream, Timeline}; @@ -18,7 +19,7 @@ use std::time::Duration; type Result = std::result::Result; #[derive(Debug)] -pub(crate) struct RedisConn { +pub(super) struct RedisConn { primary: TcpStream, secondary: TcpStream, redis_namespace: Option, @@ -29,7 +30,7 @@ pub(crate) struct RedisConn { } impl RedisConn { - pub(crate) fn new(redis_cfg: &Redis) -> Result { + pub(super) fn new(redis_cfg: &Redis) -> Result { let addr = [&*redis_cfg.host, ":", &*redis_cfg.port.to_string()].concat(); let conn = Self::new_connection(&addr, redis_cfg.password.as_ref())?; @@ -50,7 +51,7 @@ impl RedisConn { Ok(redis_conn) } - pub(crate) fn poll_redis(&mut self) -> Poll, ManagerErr> { + pub(super) fn poll_redis(&mut self) -> Poll, ManagerErr> { loop { match self.primary.read(&mut self.redis_input[self.cursor..]) { Ok(n) => { @@ -111,7 +112,7 @@ impl RedisConn { res } - pub(crate) fn update_cache(&mut self, hashtag: String, id: i64) { + pub(super) fn update_cache(&mut self, hashtag: String, id: i64) { self.tag_id_cache.put(hashtag.clone(), id); self.tag_name_cache.put(id, hashtag); } diff --git a/src/response/redis/connection/err.rs b/src/response/redis/connection/err.rs index 0707597..3b344c8 100644 --- a/src/response/redis/connection/err.rs +++ b/src/response/redis/connection/err.rs @@ -1,4 +1,4 @@ -use crate::request::TimelineErr; +use crate::request; use std::fmt; #[derive(Debug)] @@ -9,11 +9,11 @@ pub enum RedisConnErr { IncorrectPassword(String), MissingPassword, NotRedis(String), - TimelineErr(TimelineErr), + TimelineErr(request::err::Timeline), } impl RedisConnErr { - pub(crate) fn with_addr>(address: T, inner: std::io::Error) -> Self { + pub(super) fn with_addr>(address: T, inner: std::io::Error) -> Self { Self::ConnectionErr { addr: address.as_ref().to_string(), inner, @@ -57,8 +57,8 @@ impl fmt::Display for RedisConnErr { } } -impl From for RedisConnErr { - fn from(e: TimelineErr) -> RedisConnErr { +impl From for RedisConnErr { + fn from(e: request::err::Timeline) -> RedisConnErr { RedisConnErr::TimelineErr(e) } } diff --git a/src/response/redis/manager.rs b/src/response/redis/manager.rs index afb4795..39dde00 100644 --- a/src/response/redis/manager.rs +++ b/src/response/redis/manager.rs @@ -2,7 +2,7 @@ //! polled by the correct `ClientAgent`. Also manages sububscriptions and //! unsubscriptions to/from Redis. mod err; -pub(crate) use err::ManagerErr; +pub(crate) use err::Error; use super::{RedisCmd, RedisConn}; use crate::config; @@ -15,7 +15,7 @@ use std::sync::{Arc, Mutex, MutexGuard, PoisonError}; use std::time::{Duration, Instant}; use tokio::sync::{mpsc, watch}; -type Result = std::result::Result; +type Result = std::result::Result; /// The item that streams from Redis and is polled by the `ClientAgent` #[derive(Debug)] diff --git a/src/response/redis/manager/err.rs b/src/response/redis/manager/err.rs index b543520..c0207ff 100644 --- a/src/response/redis/manager/err.rs +++ b/src/response/redis/manager/err.rs @@ -1,10 +1,11 @@ use super::super::{RedisConnErr, RedisParseErr}; use crate::event::{Event, EventErr}; -use crate::request::{Timeline, TimelineErr}; +use crate::request::err::Timeline as TimelineErr; +use crate::request::Timeline; use std::fmt; #[derive(Debug)] -pub enum ManagerErr { +pub enum Error { InvalidId, TimelineErr(TimelineErr), EventErr(EventErr), @@ -13,11 +14,11 @@ pub enum ManagerErr { ChannelSendErr(tokio::sync::watch::error::SendError<(Timeline, Event)>), } -impl std::error::Error for ManagerErr {} +impl std::error::Error for Error {} -impl fmt::Display for ManagerErr { +impl fmt::Display for Error { fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { - use ManagerErr::*; + use Error::*; match self { InvalidId => write!( f, @@ -33,31 +34,31 @@ impl fmt::Display for ManagerErr { } } -impl From> for ManagerErr { +impl From> for Error { fn from(error: tokio::sync::watch::error::SendError<(Timeline, Event)>) -> Self { Self::ChannelSendErr(error) } } -impl From for ManagerErr { +impl From for Error { fn from(error: EventErr) -> Self { Self::EventErr(error) } } -impl From for ManagerErr { +impl From for Error { fn from(e: RedisConnErr) -> Self { Self::RedisConnErr(e) } } -impl From for ManagerErr { +impl From for Error { fn from(e: TimelineErr) -> Self { Self::TimelineErr(e) } } -impl From for ManagerErr { +impl From for Error { fn from(e: RedisParseErr) -> Self { Self::RedisParseErr(e) }