aboutsummaryrefslogtreecommitdiff
path: root/src/db/mod.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/db/mod.rs')
-rw-r--r--src/db/mod.rs14
1 files changed, 4 insertions, 10 deletions
diff --git a/src/db/mod.rs b/src/db/mod.rs
index db6cfb8..611526f 100644
--- a/src/db/mod.rs
+++ b/src/db/mod.rs
@@ -215,7 +215,7 @@ pub fn rare_meme(conn: &PgConnection, audio: bool) -> Result<Meme> {
let meme_id = elems.into_iter()
.find(|(_, x)| target_prob < *x)
- .ok_or(anyhow!("couldn't locate meme satisfying target probability"))?
+ .ok_or_else(|| anyhow!("couldn't locate meme satisfying target probability"))?
.0;
Meme::find(conn, meme_id)
@@ -223,7 +223,6 @@ pub fn rare_meme(conn: &PgConnection, audio: bool) -> Result<Meme> {
pub fn rand_meme(conn: &PgConnection, audio: bool) -> Result<Meme> {
use rand::{thread_rng, seq::SliceRandom};
- use std::ops::Try;
let ids: Vec<i32> = if audio {
memes::table
@@ -243,8 +242,7 @@ pub fn rand_meme(conn: &PgConnection, audio: bool) -> Result<Meme> {
};
let id = ids.choose(&mut thread_rng())
- .into_result()
- .map_err( |_| anyhow!("couldn't load meme"))?;
+ .ok_or_else(|| anyhow!("couldn't load meme"))?;
memes::table
.find(id)
@@ -254,7 +252,6 @@ pub fn rand_meme(conn: &PgConnection, audio: bool) -> Result<Meme> {
pub fn rand_audio_meme(conn: &PgConnection) -> Result<Meme> {
use rand::{thread_rng, seq::SliceRandom};
- use std::ops::Try;
let ids: Vec<i32> = memes::table
.select(memes::id)
@@ -263,8 +260,7 @@ pub fn rand_audio_meme(conn: &PgConnection) -> Result<Meme> {
.map_err(Error::from)?;
let id = ids.choose(&mut thread_rng())
- .into_result()
- .map_err(|_| anyhow!("couldn't load audio meme"))?;
+ .ok_or_else(|| anyhow!("couldn't load audio meme"))?;
memes::table
.find(id)
@@ -274,7 +270,6 @@ pub fn rand_audio_meme(conn: &PgConnection) -> Result<Meme> {
pub fn rand_silent_meme(conn: &PgConnection) -> Result<Meme> {
use rand::{thread_rng, seq::SliceRandom};
- use std::ops::Try;
let ids: Vec<i32> = memes::table
.select(memes::id)
@@ -283,8 +278,7 @@ pub fn rand_silent_meme(conn: &PgConnection) -> Result<Meme> {
.map_err(Error::from)?;
let id = ids.choose(&mut thread_rng())
- .into_result()
- .map_err(|_| anyhow!("couldn't load audio meme"))?;
+ .ok_or_else(|| anyhow!("couldn't load audio meme"))?;
memes::table
.find(id)