From ce18cfa2d67ccf6ec560d59da1753930e86d169c Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Sun, 15 Apr 2018 21:31:14 +0200 Subject: refactor: Add a message!-macro to reduce message boilerplate --- src/db.rs | 30 ++++++------------------------ 1 file changed, 6 insertions(+), 24 deletions(-) (limited to 'src/db.rs') diff --git a/src/db.rs b/src/db.rs index ad1c148a7072..202f6c1609ca 100644 --- a/src/db.rs +++ b/src/db.rs @@ -35,10 +35,7 @@ impl Actor for DbExecutor { /// Message used to request a list of threads. /// TODO: This should support page numbers. pub struct ListThreads; - -impl Message for ListThreads { - type Result = Result>; -} +message!(ListThreads, Result>); impl Handler for DbExecutor { type Result = ::Result; @@ -56,10 +53,7 @@ impl Handler for DbExecutor { /// Message used to fetch a specific thread. Returns the thread and /// its posts. pub struct GetThread(pub i32); - -impl Message for GetThread { - type Result = Result<(Thread, Vec)>; -} +message!(GetThread, Result<(Thread, Vec)>); impl Handler for DbExecutor { type Result = ::Result; @@ -82,10 +76,7 @@ pub struct CreateThread { pub new_thread: NewThread, pub post: String, } - -impl Message for CreateThread { - type Result = Result; -} +message!(CreateThread, Result); impl Handler for DbExecutor { type Result = ::Result; @@ -121,10 +112,7 @@ impl Handler for DbExecutor { /// Message used to create a new reply pub struct CreatePost(pub NewPost); - -impl Message for CreatePost { - type Result = Result; -} +message!(CreatePost, Result); impl Handler for DbExecutor { type Result = ::Result; @@ -143,10 +131,7 @@ impl Handler for DbExecutor { /// Message used to search for posts #[derive(Deserialize)] pub struct SearchPosts { pub query: String } - -impl Message for SearchPosts { - type Result = Result>; -} +message!(SearchPosts, Result>); /// Raw PostgreSQL query used to perform full-text search on posts /// with a supplied phrase. For now, the query language is hardcoded @@ -182,10 +167,7 @@ impl Handler for DbExecutor { /// Message that triggers a refresh of the view used for full-text /// searching. pub struct RefreshSearchView; - -impl Message for RefreshSearchView { - type Result = Result<()>; -} +message!(RefreshSearchView, Result<()>); const REFRESH_QUERY: &'static str = "REFRESH MATERIALIZED VIEW search_index"; -- cgit 1.4.1