From 2a38c282dd57c2051a568549d62c80d6036e8920 Mon Sep 17 00:00:00 2001 From: Nathan Perry Date: Sun, 17 Nov 2019 21:31:28 -0500 Subject: most restructuring done --- src/db/mod.rs | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) (limited to 'src/db') diff --git a/src/db/mod.rs b/src/db/mod.rs index 8702099..2a6d1f4 100644 --- a/src/db/mod.rs +++ b/src/db/mod.rs @@ -164,7 +164,6 @@ pub fn delete_meme>(conn: &PgConnection, search: T, deleted_by: u6 pub fn rare_meme(conn: &PgConnection, audio: bool) -> Result { use rand::prelude::*; - use failure::err_msg; let raw_conn = raw_connection()?; @@ -205,7 +204,7 @@ pub fn rare_meme(conn: &PgConnection, audio: bool) -> Result { .collect::>(); if elems.len() == 0 { - return Err(err_msg("no rare memes found")); + return Err(anyhow!("no rare memes found")); } let mut rng = thread_rng(); @@ -213,7 +212,7 @@ pub fn rare_meme(conn: &PgConnection, audio: bool) -> Result { let meme_id = elems.into_iter() .find(|(_, x)| target_prob < *x) - .ok_or(err_msg("couldn't locate meme satisfying target probability"))? + .ok_or(anyhow!("couldn't locate meme satisfying target probability"))? .0; Meme::find(conn, meme_id) @@ -221,7 +220,6 @@ pub fn rare_meme(conn: &PgConnection, audio: bool) -> Result { pub fn rand_meme(conn: &PgConnection, audio: bool) -> Result { use rand::{thread_rng, seq::SliceRandom}; - use failure::err_msg; use std::ops::Try; let ids: Vec = if audio { @@ -243,7 +241,7 @@ pub fn rand_meme(conn: &PgConnection, audio: bool) -> Result { let id = ids.choose(&mut thread_rng()) .into_result() - .map_err( |_| err_msg("couldn't load meme"))?; + .map_err( |_| anyhow!("couldn't load meme"))?; memes::table .find(id) @@ -253,7 +251,6 @@ pub fn rand_meme(conn: &PgConnection, audio: bool) -> Result { pub fn rand_audio_meme(conn: &PgConnection) -> Result { use rand::{thread_rng, seq::SliceRandom}; - use failure::err_msg; use std::ops::Try; let ids: Vec = memes::table @@ -264,7 +261,7 @@ pub fn rand_audio_meme(conn: &PgConnection) -> Result { let id = ids.choose(&mut thread_rng()) .into_result() - .map_err(|_| err_msg("couldn't load audio meme"))?; + .map_err(|_| anyhow!("couldn't load audio meme"))?; memes::table .find(id) @@ -274,7 +271,6 @@ pub fn rand_audio_meme(conn: &PgConnection) -> Result { pub fn rand_silent_meme(conn: &PgConnection) -> Result { use rand::{thread_rng, seq::SliceRandom}; - use failure::err_msg; use std::ops::Try; let ids: Vec = memes::table @@ -285,7 +281,7 @@ pub fn rand_silent_meme(conn: &PgConnection) -> Result { let id = ids.choose(&mut thread_rng()) .into_result() - .map_err(|_| err_msg("couldn't load audio meme"))?; + .map_err(|_| anyhow!("couldn't load audio meme"))?; memes::table .find(id) -- cgit v1.3.1