Rust 2018! (#726)

This commit is contained in:
Ana Gelez
2020-01-21 07:02:03 +01:00
committed by Igor Galić
parent 3663bffe5c
commit 5f8d6b8e0e
115 changed files with 447 additions and 582 deletions
+20 -18
View File
@@ -1,16 +1,16 @@
use crate::{
lists::List,
posts::Post,
schema::{posts, timeline, timeline_definition},
Connection, Error, PlumeRocket, Result,
};
use diesel::{self, BoolExpressionMethods, ExpressionMethods, QueryDsl, RunQueryDsl};
use lists::List;
use posts::Post;
use schema::{posts, timeline, timeline_definition};
use std::ops::Deref;
use {Connection, Error, PlumeRocket, Result};
pub(crate) mod query;
use self::query::{QueryError, TimelineQuery};
pub use self::query::Kind;
use self::query::{QueryError, TimelineQuery};
#[derive(Clone, Debug, PartialEq, Queryable, Identifiable, AsChangeset)]
#[table_name = "timeline_definition"]
@@ -208,7 +208,7 @@ impl Timeline {
.map_err(Error::from)
}
pub fn add_to_all_timelines(rocket: &PlumeRocket, post: &Post, kind: Kind) -> Result<()> {
pub fn add_to_all_timelines(rocket: &PlumeRocket, post: &Post, kind: Kind<'_>) -> Result<()> {
let timelines = timeline_definition::table
.load::<Self>(rocket.conn.deref())
.map_err(Error::from)?;
@@ -231,7 +231,7 @@ impl Timeline {
Ok(())
}
pub fn matches(&self, rocket: &PlumeRocket, post: &Post, kind: Kind) -> Result<bool> {
pub fn matches(&self, rocket: &PlumeRocket, post: &Post, kind: Kind<'_>) -> Result<bool> {
let query = TimelineQuery::parse(&self.query)?;
query.matches(rocket, self, post, kind)
}
@@ -240,16 +240,18 @@ impl Timeline {
#[cfg(test)]
mod tests {
use super::*;
use blogs::tests as blogTests;
use crate::{
blogs::tests as blogTests,
follows::*,
lists::ListType,
post_authors::{NewPostAuthor, PostAuthor},
posts::NewPost,
safe_string::SafeString,
tags::Tag,
tests::{db, rockets},
users::tests as userTests,
};
use diesel::Connection;
use follows::*;
use lists::ListType;
use post_authors::{NewPostAuthor, PostAuthor};
use posts::NewPost;
use safe_string::SafeString;
use tags::Tag;
use tests::{db, rockets};
use users::tests as userTests;
#[test]
fn test_timeline() {
+17 -17
View File
@@ -1,15 +1,15 @@
use blogs::Blog;
use lists::{self, ListType};
use crate::{
blogs::Blog,
lists::{self, ListType},
posts::Post,
tags::Tag,
timeline::Timeline,
users::User,
PlumeRocket, Result,
};
use plume_common::activity_pub::inbox::AsActor;
use posts::Post;
use tags::Tag;
use users::User;
use whatlang::{self, Lang};
use {PlumeRocket, Result};
use super::Timeline;
#[derive(Debug, Clone, PartialEq)]
pub enum QueryError {
SyntaxError(usize, usize, String),
@@ -65,7 +65,7 @@ impl<'a> Token<'a> {
}
}
fn get_error<T>(&self, token: Token) -> QueryResult<T> {
fn get_error<T>(&self, token: Token<'_>) -> QueryResult<T> {
let (b, e) = self.get_pos();
let message = format!(
"Syntax Error: Expected {}, got {}",
@@ -127,7 +127,7 @@ macro_rules! gen_tokenizer {
}
}
fn lex(stream: &str) -> Vec<Token> {
fn lex(stream: &str) -> Vec<Token<'_>> {
stream
.chars()
.chain(" ".chars()) // force a last whitespace to empty scan's state
@@ -163,7 +163,7 @@ impl<'a> TQ<'a> {
rocket: &PlumeRocket,
timeline: &Timeline,
post: &Post,
kind: Kind,
kind: Kind<'_>,
) -> Result<bool> {
match self {
TQ::Or(inner) => inner.iter().try_fold(false, |s, e| {
@@ -208,7 +208,7 @@ impl<'a> Arg<'a> {
rocket: &PlumeRocket,
timeline: &Timeline,
post: &Post,
kind: Kind,
kind: Kind<'_>,
) -> Result<bool> {
match self {
Arg::In(t, l) => t.matches(rocket, timeline, post, l, kind),
@@ -233,8 +233,8 @@ impl WithList {
rocket: &PlumeRocket,
timeline: &Timeline,
post: &Post,
list: &List,
kind: Kind,
list: &List<'_>,
kind: Kind<'_>,
) -> Result<bool> {
match list {
List::List(name) => {
@@ -374,7 +374,7 @@ impl Bool {
rocket: &PlumeRocket,
timeline: &Timeline,
post: &Post,
kind: Kind,
kind: Kind<'_>,
) -> Result<bool> {
match self {
Bool::Followed { boosts, likes } => {
@@ -645,7 +645,7 @@ impl<'a> TimelineQuery<'a> {
rocket: &PlumeRocket,
timeline: &Timeline,
post: &Post,
kind: Kind,
kind: Kind<'_>,
) -> Result<bool> {
self.0.matches(rocket, timeline, post, kind)
}